Get constant value by using string?

Hi,

My question is really simple :slight_smile:

class MyClass
ANYTHING = “huh”
end

How can I print out huh from string?

MyClass::“anything”.upcase

Is there any way to do that ?

:slight_smile:

Thanks for help…

Jamal S. wrote:

MyClass::“anything”.upcase

Is there any way to do that ?

MyClass.const_get(“anything”.upcase)

HTH,
Sebastian

On Nov 21, 2007, at 9:28 PM, Jamal S. wrote:

:slight_smile:
Sure, for example:

MyClass.module_eval(“ANYTHING”)
MyClass.const_get(“ANYTHING”)

In Rails you also have:

“MyClass::ANYTHING”.constantize

– fxn

Thanks :slight_smile: