They seem to be aliases for the same thing. From the documentation you can see that the sample code of intern
uses to_sym
:
intern → symbol
Returns the Symbol corresponding to str, creating the symbol if it did not previously exist. See
Symbol#id2name
."Koala".intern #=> :Koala s = 'cat'.to_sym #=> :cat s == :cat #=> true s = '@cat'.to_sym #=> :@cat s == :@cat #=> true
This can also be used to create symbols that cannot be represented using the :xxx notation.
'cat and dog'.to_sym #=> :"cat and dog"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With