Why would we put a module inside a class in Ruby?

后端 未结 4 671
遇见更好的自我
遇见更好的自我 2021-01-30 04:01

In Ruby, I see that it can be useful to put classes inside modules for the sake of namespacing. I also see that it\'s possible to put modules inside classes. But I don\'t see wh

4条回答
  •  隐瞒了意图╮
    2021-01-30 04:52

    class Image
        module Colors
            Red = ...
            Blue = ...
        end
        include Colors
    end
    
    include Image::Colors
    
    Image.new.set_pixel x, y, Red 
    

提交回复
热议问题