Accessing a class's constants

Jeremy Smith picture Jeremy Smith · Jun 21, 2011 · Viewed 70.1k times · Source

When I have the following:

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

  ...
end

Is there a way to access with Foo::CONSTANT_NAME or do I have to make a class method to access the value?

Answer

Dylan Markow picture Dylan Markow · Jun 21, 2011

What you posted should work perfectly:

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

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