Created
July 25, 2013 10:02
-
-
Save AlexanderPavlenko/6078400 to your computer and use it in GitHub Desktop.
JRuby's Enumerator#to_enum rebinds instance variables to another context?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BuggyEnumerator < Enumerator | |
def initialize(that) | |
@ivar = that | |
end | |
def each | |
return to_enum(:each) unless block_given? | |
@ivar.each{|item| yield item } | |
end | |
end | |
ruby-2.0.0-p195 | |
> BuggyEnumerator.new([1,2,3]).each.to_a | |
=> [1, 2, 3] | |
> BuggyEnumerator.new([1,2,3]).each_entry.to_a | |
=> [1, 2, 3] | |
ruby-1.9.3-p327 | |
> BuggyEnumerator.new([1,2,3]).each.to_a | |
=> [1, 2, 3] | |
> BuggyEnumerator.new([1,2,3]).each_entry.to_a | |
=> [1, 2, 3] | |
jruby-1.7.4 | |
> BuggyEnumerator.new([1,2,3]).each.to_a | |
=> [1, 2, 3] | |
> BuggyEnumerator.new([1,2,3]).each_entry.to_a | |
NoMethodError: undefined method `each' for nil:NilClass | |
from (irb):7:in `each' | |
from org/jruby/RubyEnumerable.java:378:in `to_a' | |
from (irb):11:in `evaluate' | |
from org/jruby/RubyKernel.java:1093:in `eval' | |
from org/jruby/RubyKernel.java:1489:in `loop' | |
from org/jruby/RubyKernel.java:1254:in `catch' | |
from org/jruby/RubyKernel.java:1254:in `catch' | |
from …/.rvm/rubies/jruby-1.7.4/bin/irb:13:in `(root)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment