🖥
Ruby | Referencing Constants
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
About
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。
公開日時
2019-04-16
Discussion