Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAbhinav Kanoria
7,730 PointsWhy the following hashes are not equivalent?
I am creating two hashes:
book1 = {"name"=>"Inferno"}
book2 = {name : "Inferno"} When I check if book1 == book2 in irb(in WorkSpaces), I get false. Are these two hashes equivalent or not?
1 Answer
Maciej Czuchnowski
36,441 PointsSymbols and strings are not the same in Ruby. You should consider them as completely different data types, since they do not respond to the same sets of methods. Just like 1 == "1"
would return false. You'd have to read more about the differences and do some experiments in the console to get the whole picture.
Rémy Lecostey
2,972 PointsRémy Lecostey
2,972 PointsBecause the book1 has a string hash key, and the book2 has a symbol hash key. For example : book3 = {:name =>"Inferno"} book3 == book2 return true, because both hash are using symbols as hash keys.