Created
August 29, 2012 22:12
-
-
Save bjeanes/3519564 to your computer and use it in GitHub Desktop.
JRuby block bug
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
JRUBY_VERSION #=> "1.7.0.preview2" # also present in 1.6.7.2 in 1.9.2 mode | |
RUBY_VERSION #=> "1.9.3" | |
data = {"x"=>[{"y"=>42}]} #=> {"x"=>[{"y"=>42}]} | |
class Hash | |
def map_as_hash | |
Hash[map { |k, v| [k, yield(v)] }] | |
end | |
end #=> nil | |
data.map_as_hash { |x| x } #=> {"x"=>[{"y"=>42}]} | |
data #=> {"x"=>[{"y"=>42}]} | |
data.map_as_hash { |x| x.first } #=> {"x"=>{"y"=>42}} | |
data #=> {"x"=>[{"y"=>42}]} | |
data.map_as_hash(&:first) #=> {"x"=>["y", 42]} | |
data #=> {"x"=>[]} |
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
JRUBY_VERSION #=> "1.7.0.preview2" # also present in 1.6.7.2 in 1.9.2 mode | |
RUBY_VERSION #=> "1.9.3" | |
data = {"x"=>[{"y"=>42}]} #=> {"x"=>[{"y"=>42}]} | |
class Hash | |
def map_as_hash(&block) | |
Hash[map { |k, v| [k, block.call(v)] }] | |
end | |
end #=> nil | |
data.map_as_hash { |x| x } #=> {"x"=>[{"y"=>42}]} | |
data #=> {"x"=>[{"y"=>42}]} | |
data.map_as_hash { |x| x.first } #=> {"x"=>{"y"=>42}} | |
data #=> {"x"=>[{"y"=>42}]} | |
data.map_as_hash(&:first) #=> {"x"=>{"y"=>42}} | |
data #=> {"x"=>[{"y"=>42}]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You're a waste of a jruby bug