Symbols can best be described as identities. A symbol is all about who it is, not what it is ๐Ÿ™Œ๐Ÿผ

The object_id method returns the identity of an Object. If two objects have the same object_id, they are the same (point to the same Object in memory).

Symbol with the same characters references the same Object in memory, and in case of String theyโ€™re referencing two different objects in memory. Whenever you use a new String, Ruby allocates memory for it.

If youโ€™re in doubt whether to use a Symbol or a String, consider whatโ€™s more important: the identity of an object (i.e. a Hash key), or the contents (in the example above, โ€œhello_worldโ€).

Code snippet ๐Ÿ“Œ

# Using Symbol
โฏ :hello_world.object_id == :hello_world.object_id

# Using String
โฏ "hello_world".object_id == "hello_world".object_id