🖥

Ruby | Referencing Constants

2019/04/16に公開

Definition

If you write the constant JAPAN in the World class.

 class World JAPAN = '日本' end 

reference

Class name :: can be referred to by a constant name.

 World::JAPAN # => "日本" 

Reference in class

The class name can be omitted if it is in the same class.

 class World JAPAN = '日本' p JAPAN end # => "日本" 

Supplement

  • I wrote because the page explaining just that wasn't hit even if I got it in "Ruby constant reference".

environment

  • Ruby 2.0.0

Original by

Ruby | 定数を参照する

About

About this translattion

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2019-04-16

Discussion