str.intern â symbol
Instance Public methods
Returns the Symbol
corresponding to str, creating the
symbol if it did not previously exist. See Symbol#id2name
.
1 2 3 4 5 | "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.
1 | 'cat and dog' .to_sym #=> :"cat and dog" |
Please login to continue.