# Java Like public constant?

**URL:** <https://www.ruby-forum.com/t/java-like-public-constant/106309>\
**Category:** Rails\
**Created:** [June 8, 2007, 11:26am UTC](https://www.ruby-forum.com/t/java-like-public-constant/106309 "2007-06-08T11:26:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Yang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a88e4f/32.png) [@Kevin\_Yang](https://www.ruby-forum.com/u/Kevin_Yang)\
**Post date:** [June 8, 2007, 11:26am UTC](https://www.ruby-forum.com/t/java-like-public-constant/106309/1 "2007-06-08T11:26:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kevin\_Yang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a88e4f/32.png) [@Kevin\_Yang](https://www.ruby-forum.com/u/Kevin_Yang)\
**Post date:** [June 8, 2007, 2:05pm UTC](https://www.ruby-forum.com/t/java-like-public-constant/106309/2 "2007-06-08T14:05:39Z")

</div>

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.
