Skip to content

Instantly share code, notes, and snippets.

@langsharpe
Created March 20, 2011 02:33
Show Gist options
  • Save langsharpe/878005 to your computer and use it in GitHub Desktop.
Save langsharpe/878005 to your computer and use it in GitHub Desktop.
Why are these two lines producing opposite outputs?
irb(main):072:0> {"a" => 0.1, "b" => 0.9}.each { |key,value| puts "#{key} is #{value}" }
a is 0.1
b is 0.9
=> {"a"=>0.1, "b"=>0.9}
irb(main):073:0> {:a => 0.1, :b => 0.9}.each { |key,value| puts "#{key} is #{value}" }
b is 0.9
a is 0.1
=> {:b=>0.9, :a=>0.1}
# Put more simply
irb(main):074:0> {:a => 0.1, :b => 0.9}
=> {:b=>0.9, :a=>0.1}
irb(main):075:0> {"a" => 0.1, "b" => 0.9}
=> {"a"=>0.1, "b"=>0.9}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment