Created
January 5, 2012 21:05
-
-
Save veryhappythings/1567277 to your computer and use it in GitHub Desktop.
Why can't you puts a hash directly?
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
[serious_business (master)↑⚡] ➔ irb | |
1.9.3p0 :001 > puts {3 => 4} | |
SyntaxError: (irb):1: syntax error, unexpected tASSOC, expecting '}' | |
puts {3 => 4} | |
^ | |
from /Users/mac/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `<main>' | |
1.9.3p0 :002 > p {3 => 4} | |
SyntaxError: (irb):2: syntax error, unexpected tASSOC, expecting '}' | |
p {3 => 4} | |
^ | |
from /Users/mac/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `<main>' | |
1.9.3p0 :003 > h = {3 => 4} | |
=> {3=>4} | |
1.9.3p0 :004 > puts h | |
{3=>4} | |
=> nil | |
1.9.3p0 :005 > |
Ah ha, I see! For some reason it didn't twig that it was interpreting it as a block. Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's interpreting the hash as a block argument to the
puts
method. Try this: