0
0

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 1 year has passed since last update.

【Rails】定数の呼び出し方

Posted at

##環境
Ruby 3.0.2
Rails 6.1.4.1

##定義と呼び出し方

class Hogehoge
  TARGET_ARTICLES_COUNT = 100.freeze
end
Hogehoge::TARGET_ARTICLES_COUNT
# => 100

他のクラスやモジュールで定義された定数を参照するには::演算子を使って定数のパスを指定。
トップレベルの定数を確実に参照するにはパスを::から始めると外部の定数を絶対パスで指定できる。

##参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?