SlideShare una empresa de Scribd logo
1 de 58
Descargar para leer sin conexión
JRuby hacking guide
David Calavera
@calavera
+70
contributors
9
core
members
~ 30
single
commits
we want
you
core
rule of
thumb
jruby-1.6.2 :003 > raise ArgumentError.new
ArgumentError: ArgumentError
    from (irb):3:in `evaluate'
    from org/jruby/RubyKernel.java:1088:in `e
    from /Users/david/.rvm/rubies/jruby-1.6.2
irb.rb:158:in `eval_input'
    from /Users/david/.rvm/rubies/jruby-1.6.2
irb.rb:271:in `signal_status'
    from /Users/david/.rvm/rubies/jruby-1.6.2
irb.rb:155:in `eval_input'
    from org/jruby/RubyKernel.java:1419:in `l
    from org/jruby/RubyKernel.java:1191:in `c
    from /Users/david/.rvm/rubies/jruby-1.6.2
irb.rb:154:in `eval_input'
    from /Users/david/.rvm/rubies/jruby-1.6.2
do not
freak out
ruby-1.8.7 :001 > raise ArgumentError.new
ArgumentError: ArgumentError
    from (irb):1
jruby-1.6.2 :001 > raise ArgumentError.new
ArgumentError: ArgumentError
    from (irb):1:in `evaluate'
    from org/jruby/RubyKernel.java:1088:in `e
    from /Users/david/.rvm/rubies/jruby-1.6.2
irb.rb:158:in `eval_input'
    from /Users/david/.rvm/rubies/jruby-1.6.2
irb.rb:271:in `signal_status'
    from /Users/david/.rvm/rubies/jruby-1.6.2
irb.rb:155:in `eval_input'
    from org/jruby/RubyKernel.java:1419:in `l
    from org/jruby/RubyKernel.java:1191:in `c
    from /Users/david/.rvm/rubies/jruby-1.6.2
irb.rb:154:in `eval_input'
    from /Users/david/.rvm/rubies/jruby-1.6.2
jruby-1.6.2 :001 > raise ArgumentError.new
ArgumentError: ArgumentError
    from (irb):1:in `evaluate'
    from org/jruby/RubyKernel.java:1088:in `e
    from /Users/david/.rvm/rubies/jruby-1.6.2
irb.rb:158:in `eval_input'
    from /Users/david/.rvm/rubies/jruby-1.6.2
irb.rb:271:in `signal_status'
    from /Users/david/.rvm/rubies/jruby-1.6.2
irb.rb:155:in `eval_input'
    from org/jruby/RubyKernel.java:1419:in `l
    from org/jruby/RubyKernel.java:1191:in `c
    from /Users/david/.rvm/rubies/jruby-1.6.2
irb.rb:154:in `eval_input'
    from /Users/david/.rvm/rubies/jruby-1.6.2
your ruby
code is our
test case
Test::Unit
def test_dir_enumerable
  Dir.mkdir("./testDir_1")

  d = Dir.new("./testDir_1")
  assert(d.kind_of?(Enumerable))
end
Rspec
describe "glob file path" do
  it "lists contents of a file" do
    dir = Dir.new(@local_file_path)
    dir.entries.should include("junit.jar")
  end
end
follow
the
specification
RubySpec
describe "Dir.entries" do
  ...

  it "returns an Array of filenames in an
existing directory including dotfiles" do
   ...
RubySpec
describe "Dir.entries" do
  ...

  ruby_version_is "1.9" do
    it "calls #to_path on ..." do
       ...
RubySpec
$ bin/jruby -S mspec 
    spec/ruby/core/dir/entries_spec.rb



$ bin/jruby --1.9 -S mspec 
    spec/ruby/core/dir/entries_spec.rb
go to the
source
ruby code
static VALUE
dir_entries(int argc, VALUE *argv, VALUE io)
{
  VALUE dir;

    dir = dir_open_dir(argc, argv);
    return rb_ensure(rb_Array, dir, dir_close, dir);
}
taming
the beast
Test::Unit
def test_dir_enumerable
  Dir.mkdir("./testDir_1")

  d = Dir.new("./testDir_1")
  assert(d.kind_of?(Enumerable))
end
Test::Unit
def test_dir_enumerable
  Dir.mkdir("./testDir_1")

  d = Dir.new("./testDir_1")
  assert(d.kind_of?(Enumerable))
end
Ruby class
$ vi src/org/jruby/RubyDir.java



@JRubyClass(name = "Dir",
            include = "Enumerable")
public class RubyDir extends RubyObject {
Ruby class
$ vi src/org/jruby/RubyDir.java



@JRubyClass(name = "Dir",
            include = "Enumerable")
public class RubyDir extends RubyObject {
Ruby class
$ vi src/org/jruby/RubyDir.java



@JRubyClass(name = "Dir",
            include = "Enumerable")
public class RubyDir extends RubyObject {
Ruby class
$ vi src/org/jruby/RubyDir.java



@JRubyClass(name = "Dir",
            include = "Enumerable")
public class RubyDir extends RubyObject {
Ruby class
$ vi src/org/jruby/RubyDir.java



@JRubyClass(name = "Dir",
            include = "Enumerable")
public class RubyDir extends RubyObject {
Test::Unit
def test_dir_enumerable
  Dir.mkdir("./testDir_1")

  d = Dir.new("./testDir_1")
  assert(d.kind_of?(Enumerable))
end
Test::Unit
def test_dir_enumerable
  Dir.mkdir("./testDir_1")

  d = Dir.new("./testDir_1")
  assert(d.kind_of?(Enumerable))
end
Ruby method
@JRubyMethod(name = "mkdir", required = 1,
optional = 1, meta = true, compat = RUBY1_8)

public static
    IRubyObject mkdir(IRubyObject recv,
    IRubyObject[] args) {
Ruby method
@JRubyMethod(name = "mkdir", required = 1,
optional = 1, meta = true, compat = RUBY1_8)

public static
    IRubyObject mkdir(IRubyObject recv,
    IRubyObject[] args) {
Ruby method
@JRubyMethod(name = "mkdir", required = 1,
optional = 1, meta = true, compat = RUBY1_8)

public static
    IRubyObject mkdir(IRubyObject recv,
    IRubyObject[] args) {
Ruby method
@JRubyMethod(name = "mkdir", required = 1,
optional = 1, meta = true, compat = RUBY1_8)

public static
    IRubyObject mkdir(IRubyObject recv,
    IRubyObject[] args) {
Ruby method
@JRubyMethod(name = "mkdir", required = 1,
optional = 1, meta = true, compat = RUBY1_8)

public static
    IRubyObject mkdir(IRubyObject recv,
    IRubyObject[] args) {
Ruby method
@JRubyMethod(name = "mkdir", required = 1,
optional = 1, meta = true, compat = RUBY1_8)

public static
    IRubyObject mkdir(IRubyObject recv,
    IRubyObject[] args) {
Ruby method
@JRubyMethod(name = "mkdir", required = 1,
optional = 1, meta = true, compat = RUBY1_8)

public static
    IRubyObject mkdir(IRubyObject recv,
    IRubyObject[] args) {
Ruby method
@JRubyMethod(name = "mkdir", required = 1,
optional = 1, meta = true, compat = RUBY1_8)

public static
    IRubyObject mkdir(IRubyObject recv,
    IRubyObject[] args) {
Ruby method
@JRubyMethod(name = "mkdir", required = 1,
optional = 1, meta = true, compat = RUBY1_8)

public static
    IRubyObject mkdir(IRubyObject recv,
    IRubyObject[] args) {
Ruby method
@JRubyMethod(name = "mkdir", required = 1,
optional = 1, meta = true, compat = RUBY1_8)

public static
    IRubyObject mkdir(IRubyObject recv,
    IRubyObject[] args) {
Test::Unit
def test_dir_enumerable
  Dir.mkdir("./testDir_1")

  d = Dir.new("./testDir_1")
  assert(d.kind_of?(Enumerable))
end
Test::Unit
def test_dir_enumerable
  Dir.mkdir("./testDir_1")

  d = Dir.new("./testDir_1")
  assert(d.kind_of?(Enumerable))
end
initialize
private static final ObjectAllocator
    DIR_ALLOCATOR = new ObjectAllocator()



@JRubyMethod(compat = RUBY1_8)
public IRubyObject initialize(IRubyObject arg)
Test::Unit
def test_dir_enumerable
  Dir.mkdir("./testDir_1")

  d = Dir.new("./testDir_1")
  assert(d.kind_of?(Enumerable))
end
Test::Unit
def test_dir_enumerable
  Dir.mkdir("./testDir_1")

  d = Dir.new("./testDir_1")
  assert(d.kind_of?(Enumerable))
end
Ruby module
$ vi src/org/jruby/RubyKernel.java



@JRubyModule(name="Kernel")
public class RubyKernel {
Ruby module
$ vi src/org/jruby/RubyKernel.java



@JRubyModule(name="Kernel")
public class RubyKernel {
Ruby module
$ vi src/org/jruby/RubyObject.java



@JRubyClass(name="Object", include="Kernel")
public class RubyObject extends ... {
Ruby module
@JRubyMethod(name = {"kind_of?", "is_a?"},
             required = 1)

public static RubyBoolean kind_of_p
(ThreadContext context,
 IRubyObject recv,
 IRubyObject type) {
Ruby module
@JRubyMethod(name = {"kind_of?", "is_a?"},
             required = 1)

public static RubyBoolean kind_of_p
(ThreadContext context,
 IRubyObject recv,
 IRubyObject type) {
Ruby module
@JRubyMethod(name = {"kind_of?", "is_a?"},
             required = 1)

public static RubyBoolean kind_of_p
(ThreadContext context,
 IRubyObject recv,
 IRubyObject type) {
learn more
http://tinyurl.com/
jruby-hacking-guide
    by Hiroshi Nakamura
http://tinyurl.com/
  distilling-jruby
     by R.J. Lorimer
http://jruby.org
thank you!
Credits
Charles Nutter’s Photo Booth
http://www.flickr.com/photos/zpeckler/2648345658/
http://www.flickr.com/photos/dcmetroblogger/3298543398/

http://www.flickr.com/photos/jenny-pics/4520503357/

Más contenido relacionado

La actualidad más candente

Spock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestSpock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestHoward Lewis Ship
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
 
Node.js System: The Landing
Node.js System: The LandingNode.js System: The Landing
Node.js System: The LandingHaci Murat Yaman
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserHoward Lewis Ship
 
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -Kenji Tanaka
 
G*におけるソフトウェアテスト・シーズンIII
G*におけるソフトウェアテスト・シーズンIIIG*におけるソフトウェアテスト・シーズンIII
G*におけるソフトウェアテスト・シーズンIIITakuma Watabiki
 
Kotlin is charming; The reasons Java engineers should start Kotlin.
Kotlin is charming; The reasons Java engineers should start Kotlin.Kotlin is charming; The reasons Java engineers should start Kotlin.
Kotlin is charming; The reasons Java engineers should start Kotlin.JustSystems Corporation
 
Using Reflections and Automatic Code Generation
Using Reflections and Automatic Code GenerationUsing Reflections and Automatic Code Generation
Using Reflections and Automatic Code GenerationIvan Dolgushin
 
Kotlin coroutines and spring framework
Kotlin coroutines and spring frameworkKotlin coroutines and spring framework
Kotlin coroutines and spring frameworkSunghyouk Bae
 
Gpars concepts explained
Gpars concepts explainedGpars concepts explained
Gpars concepts explainedVaclav Pech
 
Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介Kiyotaka Oku
 
Writing native bindings to node.js in C++
Writing native bindings to node.js in C++Writing native bindings to node.js in C++
Writing native bindings to node.js in C++nsm.nikhil
 
Everything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap DumpsEverything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap DumpsAndrei Pangin
 

La actualidad más candente (20)

Spock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestSpock: A Highly Logical Way To Test
Spock: A Highly Logical Way To Test
 
Groovy.pptx
Groovy.pptxGroovy.pptx
Groovy.pptx
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Node.js System: The Landing
Node.js System: The LandingNode.js System: The Landing
Node.js System: The Landing
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
 
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
 
Spockを使おう!
Spockを使おう!Spockを使おう!
Spockを使おう!
 
G*におけるソフトウェアテスト・シーズンIII
G*におけるソフトウェアテスト・シーズンIIIG*におけるソフトウェアテスト・シーズンIII
G*におけるソフトウェアテスト・シーズンIII
 
Python Objects
Python ObjectsPython Objects
Python Objects
 
Kotlin is charming; The reasons Java engineers should start Kotlin.
Kotlin is charming; The reasons Java engineers should start Kotlin.Kotlin is charming; The reasons Java engineers should start Kotlin.
Kotlin is charming; The reasons Java engineers should start Kotlin.
 
Using Reflections and Automatic Code Generation
Using Reflections and Automatic Code GenerationUsing Reflections and Automatic Code Generation
Using Reflections and Automatic Code Generation
 
Kotlin coroutines and spring framework
Kotlin coroutines and spring frameworkKotlin coroutines and spring framework
Kotlin coroutines and spring framework
 
Gpars concepts explained
Gpars concepts explainedGpars concepts explained
Gpars concepts explained
 
Hamcrest
HamcrestHamcrest
Hamcrest
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Groovy
GroovyGroovy
Groovy
 
Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介
 
Writing native bindings to node.js in C++
Writing native bindings to node.js in C++Writing native bindings to node.js in C++
Writing native bindings to node.js in C++
 
Everything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap DumpsEverything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap Dumps
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 

Destacado

Rubyspec y el largo camino hacia Ruby 1.9
Rubyspec y el largo camino hacia Ruby 1.9Rubyspec y el largo camino hacia Ruby 1.9
Rubyspec y el largo camino hacia Ruby 1.9David Calavera
 
Egyptian Aeraunautical Sports Club Guide
Egyptian Aeraunautical Sports Club GuideEgyptian Aeraunautical Sports Club Guide
Egyptian Aeraunautical Sports Club Guideahmad bassiouny
 
ApacheCon: Abdera A Java Atom Pub Implementation
ApacheCon: Abdera A Java Atom Pub ImplementationApacheCon: Abdera A Java Atom Pub Implementation
ApacheCon: Abdera A Java Atom Pub ImplementationDavid Calavera
 
Life-feed | final presentation
Life-feed  |  final presentationLife-feed  |  final presentation
Life-feed | final presentationPixelkings
 
GTAC: AtomPub, testing your server implementation
GTAC: AtomPub, testing your server implementationGTAC: AtomPub, testing your server implementation
GTAC: AtomPub, testing your server implementationDavid Calavera
 
Conferencia Rails: Integracion Continua Y Rails
Conferencia Rails: Integracion Continua Y RailsConferencia Rails: Integracion Continua Y Rails
Conferencia Rails: Integracion Continua Y RailsDavid Calavera
 

Destacado (8)

Trinidad
TrinidadTrinidad
Trinidad
 
Rubyspec y el largo camino hacia Ruby 1.9
Rubyspec y el largo camino hacia Ruby 1.9Rubyspec y el largo camino hacia Ruby 1.9
Rubyspec y el largo camino hacia Ruby 1.9
 
Egyptian Aeraunautical Sports Club Guide
Egyptian Aeraunautical Sports Club GuideEgyptian Aeraunautical Sports Club Guide
Egyptian Aeraunautical Sports Club Guide
 
ApacheCon: Abdera A Java Atom Pub Implementation
ApacheCon: Abdera A Java Atom Pub ImplementationApacheCon: Abdera A Java Atom Pub Implementation
ApacheCon: Abdera A Java Atom Pub Implementation
 
Life-feed | final presentation
Life-feed  |  final presentationLife-feed  |  final presentation
Life-feed | final presentation
 
My name is Trinidad
My name is TrinidadMy name is Trinidad
My name is Trinidad
 
GTAC: AtomPub, testing your server implementation
GTAC: AtomPub, testing your server implementationGTAC: AtomPub, testing your server implementation
GTAC: AtomPub, testing your server implementation
 
Conferencia Rails: Integracion Continua Y Rails
Conferencia Rails: Integracion Continua Y RailsConferencia Rails: Integracion Continua Y Rails
Conferencia Rails: Integracion Continua Y Rails
 

Similar a JRuby hacking guide

Practical Testing of Ruby Core
Practical Testing of Ruby CorePractical Testing of Ruby Core
Practical Testing of Ruby CoreHiroshi SHIBATA
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2rubyMarc Chung
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
JRuby @ Boulder Ruby
JRuby @ Boulder RubyJRuby @ Boulder Ruby
JRuby @ Boulder RubyNick Sieger
 
A jar-nORM-ous Task
A jar-nORM-ous TaskA jar-nORM-ous Task
A jar-nORM-ous TaskErin Dees
 
Spocktacular Testing - Russel Winder
Spocktacular Testing - Russel WinderSpocktacular Testing - Russel Winder
Spocktacular Testing - Russel WinderJAXLondon2014
 
Spocktacular Testing
Spocktacular TestingSpocktacular Testing
Spocktacular TestingRussel Winder
 
Практики применения JRuby
Практики применения JRubyПрактики применения JRuby
Практики применения JRuby.toster
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Mario Camou Riveroll
 
Assignment #2.classpathAssignment #2.project Assig.docx
Assignment #2.classpathAssignment #2.project  Assig.docxAssignment #2.classpathAssignment #2.project  Assig.docx
Assignment #2.classpathAssignment #2.project Assig.docxfredharris32
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - GuilinJackson Tian
 
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012rivierarb
 
Spock: Test Well and Prosper
Spock: Test Well and ProsperSpock: Test Well and Prosper
Spock: Test Well and ProsperKen Kousen
 
IndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceIndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceParashuram N
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1Jano Suchal
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes BackBurke Libbey
 

Similar a JRuby hacking guide (20)

Practical Testing of Ruby Core
Practical Testing of Ruby CorePractical Testing of Ruby Core
Practical Testing of Ruby Core
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
 
How to write Ruby extensions with Crystal
How to write Ruby extensions with CrystalHow to write Ruby extensions with Crystal
How to write Ruby extensions with Crystal
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Ruby tricks2
Ruby tricks2Ruby tricks2
Ruby tricks2
 
JRuby @ Boulder Ruby
JRuby @ Boulder RubyJRuby @ Boulder Ruby
JRuby @ Boulder Ruby
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
 
A jar-nORM-ous Task
A jar-nORM-ous TaskA jar-nORM-ous Task
A jar-nORM-ous Task
 
Spocktacular Testing - Russel Winder
Spocktacular Testing - Russel WinderSpocktacular Testing - Russel Winder
Spocktacular Testing - Russel Winder
 
Spocktacular Testing
Spocktacular TestingSpocktacular Testing
Spocktacular Testing
 
Практики применения JRuby
Практики применения JRubyПрактики применения JRuby
Практики применения JRuby
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?
 
Assignment #2.classpathAssignment #2.project Assig.docx
Assignment #2.classpathAssignment #2.project  Assig.docxAssignment #2.classpathAssignment #2.project  Assig.docx
Assignment #2.classpathAssignment #2.project Assig.docx
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - Guilin
 
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
 
Spock: Test Well and Prosper
Spock: Test Well and ProsperSpock: Test Well and Prosper
Spock: Test Well and Prosper
 
IndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceIndexedDB - Querying and Performance
IndexedDB - Querying and Performance
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1
 
Message in a bottle
Message in a bottleMessage in a bottle
Message in a bottle
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
 

JRuby hacking guide

  • 1. JRuby hacking guide David Calavera @calavera
  • 8. jruby-1.6.2 :003 > raise ArgumentError.new ArgumentError: ArgumentError from (irb):3:in `evaluate' from org/jruby/RubyKernel.java:1088:in `e from /Users/david/.rvm/rubies/jruby-1.6.2 irb.rb:158:in `eval_input' from /Users/david/.rvm/rubies/jruby-1.6.2 irb.rb:271:in `signal_status' from /Users/david/.rvm/rubies/jruby-1.6.2 irb.rb:155:in `eval_input' from org/jruby/RubyKernel.java:1419:in `l from org/jruby/RubyKernel.java:1191:in `c from /Users/david/.rvm/rubies/jruby-1.6.2 irb.rb:154:in `eval_input' from /Users/david/.rvm/rubies/jruby-1.6.2
  • 10. ruby-1.8.7 :001 > raise ArgumentError.new ArgumentError: ArgumentError from (irb):1
  • 11. jruby-1.6.2 :001 > raise ArgumentError.new ArgumentError: ArgumentError from (irb):1:in `evaluate' from org/jruby/RubyKernel.java:1088:in `e from /Users/david/.rvm/rubies/jruby-1.6.2 irb.rb:158:in `eval_input' from /Users/david/.rvm/rubies/jruby-1.6.2 irb.rb:271:in `signal_status' from /Users/david/.rvm/rubies/jruby-1.6.2 irb.rb:155:in `eval_input' from org/jruby/RubyKernel.java:1419:in `l from org/jruby/RubyKernel.java:1191:in `c from /Users/david/.rvm/rubies/jruby-1.6.2 irb.rb:154:in `eval_input' from /Users/david/.rvm/rubies/jruby-1.6.2
  • 12. jruby-1.6.2 :001 > raise ArgumentError.new ArgumentError: ArgumentError from (irb):1:in `evaluate' from org/jruby/RubyKernel.java:1088:in `e from /Users/david/.rvm/rubies/jruby-1.6.2 irb.rb:158:in `eval_input' from /Users/david/.rvm/rubies/jruby-1.6.2 irb.rb:271:in `signal_status' from /Users/david/.rvm/rubies/jruby-1.6.2 irb.rb:155:in `eval_input' from org/jruby/RubyKernel.java:1419:in `l from org/jruby/RubyKernel.java:1191:in `c from /Users/david/.rvm/rubies/jruby-1.6.2 irb.rb:154:in `eval_input' from /Users/david/.rvm/rubies/jruby-1.6.2
  • 13. your ruby code is our test case
  • 14. Test::Unit def test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable)) end
  • 15. Rspec describe "glob file path" do it "lists contents of a file" do dir = Dir.new(@local_file_path) dir.entries.should include("junit.jar") end end
  • 17. RubySpec describe "Dir.entries" do ... it "returns an Array of filenames in an existing directory including dotfiles" do ...
  • 18. RubySpec describe "Dir.entries" do ... ruby_version_is "1.9" do it "calls #to_path on ..." do ...
  • 19. RubySpec $ bin/jruby -S mspec spec/ruby/core/dir/entries_spec.rb $ bin/jruby --1.9 -S mspec spec/ruby/core/dir/entries_spec.rb
  • 21. ruby code static VALUE dir_entries(int argc, VALUE *argv, VALUE io) { VALUE dir; dir = dir_open_dir(argc, argv); return rb_ensure(rb_Array, dir, dir_close, dir); }
  • 23. Test::Unit def test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable)) end
  • 24. Test::Unit def test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable)) end
  • 25. Ruby class $ vi src/org/jruby/RubyDir.java @JRubyClass(name = "Dir", include = "Enumerable") public class RubyDir extends RubyObject {
  • 26. Ruby class $ vi src/org/jruby/RubyDir.java @JRubyClass(name = "Dir", include = "Enumerable") public class RubyDir extends RubyObject {
  • 27. Ruby class $ vi src/org/jruby/RubyDir.java @JRubyClass(name = "Dir", include = "Enumerable") public class RubyDir extends RubyObject {
  • 28. Ruby class $ vi src/org/jruby/RubyDir.java @JRubyClass(name = "Dir", include = "Enumerable") public class RubyDir extends RubyObject {
  • 29. Ruby class $ vi src/org/jruby/RubyDir.java @JRubyClass(name = "Dir", include = "Enumerable") public class RubyDir extends RubyObject {
  • 30. Test::Unit def test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable)) end
  • 31. Test::Unit def test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable)) end
  • 32. Ruby method @JRubyMethod(name = "mkdir", required = 1, optional = 1, meta = true, compat = RUBY1_8) public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 33. Ruby method @JRubyMethod(name = "mkdir", required = 1, optional = 1, meta = true, compat = RUBY1_8) public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 34. Ruby method @JRubyMethod(name = "mkdir", required = 1, optional = 1, meta = true, compat = RUBY1_8) public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 35. Ruby method @JRubyMethod(name = "mkdir", required = 1, optional = 1, meta = true, compat = RUBY1_8) public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 36. Ruby method @JRubyMethod(name = "mkdir", required = 1, optional = 1, meta = true, compat = RUBY1_8) public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 37. Ruby method @JRubyMethod(name = "mkdir", required = 1, optional = 1, meta = true, compat = RUBY1_8) public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 38. Ruby method @JRubyMethod(name = "mkdir", required = 1, optional = 1, meta = true, compat = RUBY1_8) public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 39. Ruby method @JRubyMethod(name = "mkdir", required = 1, optional = 1, meta = true, compat = RUBY1_8) public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 40. Ruby method @JRubyMethod(name = "mkdir", required = 1, optional = 1, meta = true, compat = RUBY1_8) public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 41. Ruby method @JRubyMethod(name = "mkdir", required = 1, optional = 1, meta = true, compat = RUBY1_8) public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 42. Test::Unit def test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable)) end
  • 43. Test::Unit def test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable)) end
  • 44. initialize private static final ObjectAllocator DIR_ALLOCATOR = new ObjectAllocator() @JRubyMethod(compat = RUBY1_8) public IRubyObject initialize(IRubyObject arg)
  • 45. Test::Unit def test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable)) end
  • 46. Test::Unit def test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable)) end
  • 47. Ruby module $ vi src/org/jruby/RubyKernel.java @JRubyModule(name="Kernel") public class RubyKernel {
  • 48. Ruby module $ vi src/org/jruby/RubyKernel.java @JRubyModule(name="Kernel") public class RubyKernel {
  • 49. Ruby module $ vi src/org/jruby/RubyObject.java @JRubyClass(name="Object", include="Kernel") public class RubyObject extends ... {
  • 50. Ruby module @JRubyMethod(name = {"kind_of?", "is_a?"}, required = 1) public static RubyBoolean kind_of_p (ThreadContext context, IRubyObject recv, IRubyObject type) {
  • 51. Ruby module @JRubyMethod(name = {"kind_of?", "is_a?"}, required = 1) public static RubyBoolean kind_of_p (ThreadContext context, IRubyObject recv, IRubyObject type) {
  • 52. Ruby module @JRubyMethod(name = {"kind_of?", "is_a?"}, required = 1) public static RubyBoolean kind_of_p (ThreadContext context, IRubyObject recv, IRubyObject type) {
  • 58. Credits Charles Nutter’s Photo Booth http://www.flickr.com/photos/zpeckler/2648345658/ http://www.flickr.com/photos/dcmetroblogger/3298543398/ http://www.flickr.com/photos/jenny-pics/4520503357/