Ruby symbol and string does the same thing except symbol is more efficient in terms of memory and time.
As explained here
A Symbol is the most basic Ruby object you can create. It’s just a name and an internal ID. Symbols are useful because a given symbol name refers to the same object throughout a Ruby program. Symbols are more efficient than strings. Two strings with the same contents are two different objects, but for any given name there is only one Symbol object. This can save both time and memory.
Therefore, when do we use a string versus a symbol?
- If the contents (the sequence of characters) of the object are important, use a string
- If the identity of the object is important, use a symbol.
We can change them to each other like this
puts “string”.to_sym.class # Symbol
puts :symbol.to_s.class # String
Symbols are particularly useful when creating hashes and you want to have a distinction between keys and values.