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 # w ww . jav a2 s  . 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