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 ww  . j ava  2  s  .  com
                        
  class Y       
  end  
  
end 

X::A 

ob = X::Y.new

Related Topic