Last active
December 14, 2015 15:19
-
-
Save urbanautomaton/5106942 to your computer and use it in GitHub Desktop.
jruby destructuring oddity
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
pairs = [[1,1],[2,2],[3,3]] | |
enumerator = Enumerator.new do |y| | |
pairs.each { |x| y.yield(x) } | |
end | |
puts "Array:" | |
puts pairs.find {|a,b| a > 2}.inspect | |
puts pairs.find {|a,b| b > 2}.inspect | |
puts "\nEnumerator:" | |
puts enumerator.find {|a,b| a > 2}.inspect | |
puts enumerator.find {|a,b| b > 2}.inspect |
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
# MRI 1.9.3-p385 | |
$ ruby enumerator.rb | |
Array: | |
[3,3] | |
[3,3] | |
Enumerator: | |
[3,3] | |
[3,3] | |
# Jruby 1.7.3 | |
$ ruby enumerator.rb | |
Array: | |
[3, 3] | |
[3, 3] | |
Enumerator: | |
3 | |
NoMethodError: undefined method `>' for nil:NilClass | |
(root) at enumerator.rb:13 | |
call at org/jruby/RubyProc.java:249 | |
yield at org/jruby/RubyYielder.java:86 | |
(root) at enumerator.rb:4 | |
each at org/jruby/RubyArray.java:1613 | |
(root) at enumerator.rb:4 | |
call at org/jruby/RubyProc.java:249 | |
each at file:/Users/simon/.rubies/jruby-1.7.3/lib/jruby.jar!/jruby/kernel/jruby/generator.rb:246 | |
each at org/jruby/RubyEnumerator.java:206 | |
find at org/jruby/RubyEnumerable.java:563 | |
(root) at enumerator.rb:13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment