Skip to content

Instantly share code, notes, and snippets.

@sunkencity
Created March 16, 2011 15:17
Show Gist options
  • Save sunkencity/872644 to your computer and use it in GitHub Desktop.
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?
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>
@sunkencity
Copy link
Author

a = [1,2,3].map do |x|x+1 end.inspect
puts a

[2, 3, 4]

@sunkencity
Copy link
Author

only jruby seems to be returning the correct result

@sunkencity
Copy link
Author

 x = {}.tap do |hsh|
   hsh[:foo] = :bar 
 end
 puts x.inspect 

{:foo=>:bar}

@sunkencity
Copy link
Author

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