Created
March 16, 2011 15:17
-
-
Save sunkencity/872644 to your computer and use it in GitHub Desktop.
in 1.9.2 do ... end blocks return an enumerator, in 1.8.7 nil, but return the same as {} if assigned to a var. why?
This file contains hidden or 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
puts [1,2,3].map {|x|x+1}.inspect | |
#[2, 3, 4] | |
puts [1,2,3].map do |x|x+1 end.inspect | |
#<Enumerator:0x00000100868110> |
only jruby seems to be returning the correct result
x = {}.tap do |hsh|
hsh[:foo] = :bar
end
puts x.inspect
{:foo=>:bar}
puts {}.tap do |hsh|
hsh[:foo] = :bar
end.inspect
NoMethodError: undefined method `[]=' for nil:NilClass
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a = [1,2,3].map do |x|x+1 end.inspect
puts a
[2, 3, 4]