-4

Which two of these three expressions are equal? Why?

{ "city" => "Miami", "state" => "Florida" }
{ :city => "Miami", :state => "Florida" }
{ city: "Miami", state: "Florida" }

1 Answers1

3

There is a great discussion on using a Ruby :symbol vs a String in another question here.

And here's a nice discussion about the difference between the fat arrow => syntax vs colons : in Ruby.

You can quickly check that the two hashes using :symbols are equivalent to each other, which are both different from the hash using strings:

a = {"city" => "Miami", "state" => "Florida"}
b = {:city => "Miami", :state => "Florida"}
c = {city: "Miami", state: "Florida"}

a == b
=> false

a == c
=> false

b == c
=> true
calebkm
  • 1,013
  • 4
  • 17