4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

気になる言葉メモ

Last updated at Posted at 2014-06-23

シンボル

シンボルとは「文字列を整数で表したもの」です。

  • シンボルを作るとRubyの内部では「文字列→一意の整数」の変換が行われ、整数値として管理される。

  • シンボルは1つの文字列が1つのオブジェクトに1対1で対応する

  • シンボルの内容は変更できない。upcase!のような!付きのメソッドを持たない。

多くのRubyプログラマーは、ソースコードの可読性を高める目的でシンボルを使います。シンボルを使えば、ある文字列が特別な意味を持つ「名前」を表していることを明示できます。また、"name"よりも:nameの方が書きやすいという理由もあります。

ミックスイン

Rubyにはクラスに似たものとして モジュール があります。
「module モジュール名 〜end」でモジュールを定義し、その中にメソッドを記述できます。

4
4
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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?