jruby/jruby — pull request #1252 by tedpennings (2013-12-02 02:57:39+00:00)
Title: Range#size missing from JRuby 1.7.8 in 2.0 mode

Range#size appears to be missing from the latest JRuby in Ruby 2.0.0 mode. Range#size was added to Ruby in 2.0.0. The other new Range methods added, like #bsearch, appear to be there -- only #range is missing.

```
irb(main):055:0> puts RUBY_VERSION
2.0.0
=> nil
irb(main):056:0> puts JRUBY_VERSION
1.7.8
=> nil
irb(main):057:0> (80..85).class
=> Range
irb(main):058:0> (80..85).size
NoMethodError: undefined method `size' for 80..85:Range
from (irb):58:in `evaluate'
from org/jruby/RubyKernel.java:1123:in `eval'
from org/jruby/RubyKernel.java:1519:in `loop'
from org/jruby/RubyKernel.java:1284:in `catch'
from org/jruby/RubyKernel.java:1284:in `catch'
from /Users/n0173592/.rvm/rubies/jruby-1.7.8/bin/irb:13:in `(root)'
irb(main):059:0> (80..85).first
=> 80
irb(main):060:0> (80..85).respond_to? :size
=> false
```

Enumerator#size appears to be defective and may be related:
```
# same session as above -- 1.7.8 in 2.0 mode
irb(main):061:0> [1,2,3,4]
=> [1, 2, 3, 4]
irb(main):062:0> [1,2,3,4].class
=> Array
irb(main):063:0> [1,2,3,4].each.size
=> nil # should be 4
irb(main):064:0> [1,2,3,4].each.class
=> Enumerator
irb(main):065:0> [1,2,3,4].each.respond_to? :size
=> true
```

For comparison, here's the MRI 2.0 behavior:
```
2.0.0p247 :001 > RUBY_VERSION
=> "2.0.0"
2.0.0p247 :002 > JRUBY_VERSION
NameError: uninitialized constant JRUBY_VERSION
from (irb):2
from /Users/n0173592/.rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `

'
2.0.0p247 :003 > (80..85).class
=> Range
2.0.0p247 :004 > (80..85).size
=> 6
2.0.0p247 :005 > (80..85).first
=> 80
2.0.0p247 :006 > (80..85).respond_to? :size
=> true
2.0.0p247 :007 > [1,2,3,4].each.size
=> 4
2.0.0p247 :008 > [1,2,3,4].each.class
=> Enumerator
2.0.0p247 :009 > [1,2,3,4].each.respond_to? :size
=> true
```

I'd be happy to send in a PR for this if you could point me in the direction of where this should be implemented. It looks like the RubyRange.java and RubyEnumerator.java classes are probably the most obvious places, but I wanted to ask before just sending in a PR for that (+tests).