Skip to content

Instantly share code, notes, and snippets.

@bjeanes
Created August 29, 2012 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjeanes/3519564 to your computer and use it in GitHub Desktop.
Save bjeanes/3519564 to your computer and use it in GitHub Desktop.
JRuby block bug
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"=>[]}
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}]}
@anathematic
Copy link

You're a waste of a jruby bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment