LoginSignup
1
0

moduleのselfのclassの定数を外部から参照する

Posted at

これを参照したい

moduleのselfのclassの中にある定数を参照したい

module Service
  class << self
    # バケット名
    BUCKET_NAME = ENV['BUCKET_NAME'] || "bucket-dev"

結論

singleton_classを間に挟む。

Service.singleton_class::BUCKET_NAME

こんなことしなくても

module直下に書けばSerive::BUCEKT_NAMEで参照できます。

module Service
  # バケット名
  BUCKET_NAME = ENV['BUCKET_NAME'] || "bucket-dev"

  class << self
1
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
1
0