Ruby - Create nested class

Introduction

Class names are constants, so this same operator gives you access to classes inside other classes.

This makes it possible to create objects from "nested" classes such as class Y inside class X:

Demo

class X 
  A = 10 # from w  w  w . ja v a2  s.co  m
                        
  class Y       
  end  
  
end 

X::A 

ob = X::Y.new

Related Topic