The distinguish of module , class when nested in ruby

For Module can't be instance , so can't call it directily , include it to class , new the class and call module.

module M1
  module M2
    class C3
      def two
        p 'this is two'
      end
    end
    def one
      p 'this is one'
    end
  end
end

class C1
  include M1
  include M1::M2
end

class C2
  include C1::M2
end
C1::C3.new.two
C1.new.one
C2.new.one

#result
#"this is two"
#"this is one"
#"this is one"


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章