Method: String#intern
- Defined in:
- string.c
#intern ⇒ Object #to_sym ⇒ Object
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"
4398 4399 4400 |
# File 'string.c', line 4398 VALUE rb_str_intern(s) VALUE s; |