Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
String#to_sym
() -> ::Symbol
to_sym
string.c
View on GitHub ↗
VALUE
rb_str_intern(VALUE str)
{
return sym_find_or_insert_dynamic_symbol(&ruby_global_symbols, str);
}
Alias of #intern
Returns the Symbol object derived from self, creating it if it did not already exist:
Example
'foo'.intern # => :foo 'こんにちは'.intern # => :こんにちは
Related: see Converting to Non-String.