Forum: Ruby on Rails Java Like public constant ?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
F78258e63d2879413ebf4558d74c1a9e?d=identicon&s=25 Kevin Yang (Guest)
on 2007-06-08 11:26
(Received via mailing list)
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?

B1edc6a4aa373d980b49e600923df552?d=identicon&s=25 Douglas Shearer (dougal)
on 2007-06-08 14:05
Kevin Yang wrote:

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

class Foo

  BAR = 12345

  def bar


> Foo::BAR
=> 12345

# or

=> 12345

The bar method is only a convenience, and ca be discarded if you don't
mind the :: notation.
This topic is locked and can not be replied to.