LoginSignup
14
11

More than 5 years have passed since last update.

Ruby | 文字列からシンボルへの変換 String#intern の命名の由来

Posted at

Ruby | 文字列からシンボルへの変換 String#intern の命名の由来

概要

文字列からシンボルへの変換 String#intern の命名の由来について

String#intern とは?

るりま String#intern / to_sym

文字列に対応するシンボルを返すメソッドです。
String#to_sym と同じ。

サンプルコード

p "hoge".intern
p "hoge".to_sym
p "hoge".to_sym == "hoge".intern

出力

:hoge
:hoge
true

String#intern の命名の由来

Ruby メーリングリストに由来がありました。

ruby-dev

まつもと ゆきひろです

|原です。
|
|また気まぐれなリクエストです。この前 once をどう定義するかと
|いうやりとりを見ていて思ったのですが、Fixnum#id2name がある
|のだから、
|
|String#name2id
|
|があってもいいのではないでしょうか。

String#internってのがあります.名前が気に入らないかも知れま
せんが我慢して下さい.lisp由来の名前です.

intern とは?

Wikipedia String intering

In computer science, string interning is a method of storing only one copy of each distinct string value, which must be immutable.
Interning strings makes some string processing tasks more time- or space-efficient at the cost of requiring more time when the string is created or interned.
The distinct values are stored in a string intern pool.

:books: 外部資料

14
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
11