skye.shaw
7/25/2007 4:26:00 AM
On Jul 24, 1:21 pm, Harnish Botadra <harnish_...@yahoo.com> wrote:
> Hi,
>
> I am having some difficulty in the use of constants in Ruby. I've a
> module:
>
> eg.
> -------------------
> Module Constants
Use lowercase "m"
> I include this module in my model. Further, the name of the constant
> (MY_CONST) would be passed in a variable say 'var'. My question, is how
> do I access the value of the constant from the constant name in 'var'?
module Constants
GRR="burr!"
end
class Bs
include Constants
def self.get_constant(name)
self.const_get(name.to_sym)
end
end
p Bs.get_constant("GRR")
Why do you need to access constants this way?