DEV Community

pooyaalamdari
pooyaalamdari

Posted on

nesting modules and classes

create instance from classes that is in module

module Tools
    class Hammer

    end
end

h = Tools::Hammer.new
Enter fullscreen mode Exit fullscreen mode

this technique can help it two classes have a similar name but are NOT the same class!
for example:

Tools::Hammer.new
Enter fullscreen mode Exit fullscreen mode

and

Piano::Hammer.new
Enter fullscreen mode Exit fullscreen mode

Tool is one case and Piano is another

Top comments (0)