どうも、ちょげ(@chogetarou)です。
文字列(string)をシンボル(symbol)に変換する方法を紹介します。
方法

文字列(string)をシンボル(symbol)に変換するには、to_symメソッドを使います。
具体的な方法としては、「str.to_sym」のように、文字列からto_symメソッドを呼び出します。
#str=対象の文字列
result = str.to_sym
上記のto_symメソッドは、文字列をシンボルに変換した結果を返します。
使用例
text = "Apple"
result = text.to_sym
p result
出力:
:Apple
コメント