Java Like public constant?


#1

Hi ,

Some times there is a need to to store some constant variables in

a Ruby Class.

we can do that in Java like :
Public Static Class A{
public static int LUCKY_NUMBER=100;
}

then we can use it everywhere A.LUCKY_NUMBER

was wondering how can I do the same thing in Ruby?

thanks
Kevin


#2

Kevin Yang wrote:

was wondering how can I do the same thing in Ruby?

class Foo

BAR = 12345

def bar
BAR
end

end

Foo::BAR
=> 12345

or

Foo.bar
=> 12345

The bar method is only a convenience, and ca be discarded if you don’t
mind the :: notation.