Ruby - Put class into modules

Introduction

The following code adds two classes with the same name, but in different modules:

Demo

module ToolBox 
  class Ruler # from  w w w .  j  a va  2s  .  c  o m
    attr_accessor :length 
  end 
end 
module Country 
  class Ruler 
    attr_accessor :name 
  end 
end 

a = ToolBox::Ruler.new 
a.length = 50 
b = Country::Ruler.new 
b.name = "test"

Related Topic