Ruby - Constants in Class

Introduction

You can access constants declared inside a class.

The constants are identifiers beginning with a capital letter.

To access the constant A, you would need to use the special scope resolution operator :: like this:

Demo

class X 
  A = 10 # from  w w  w.  j  a va  2 s .  com
                        
  class Y       
  end  
  
end 

X::A

Related Topic