Accessing a class's constants

后端 未结 4 845
一个人的身影
一个人的身影 2020-12-24 00:00

When I have the following:

class Foo
   CONSTANT_NAME = [\"a\", \"b\", \"c\"]

  ...
end

Is there a way to access with Foo::CONSTANT_

4条回答
  •  猫巷女王i
    2020-12-24 00:38

    What you posted should work perfectly:

    class Foo
      CONSTANT_NAME = ["a", "b", "c"]
    end
    
    Foo::CONSTANT_NAME
    # => ["a", "b", "c"]
    

提交回复
热议问题