class Dog
def include_mod # not workable
include Mod
end
def self.include_mod #workable
include Mod
end
end
module Mod
def shat
puts "shat"
end
end
dog = Dog.new
dog.class.include_mod
puts Dog.instance_method :shat
dog.include_mod
#'include' is a method belonging to Module
#Class inherit Module, so Class can include
#And 'include' is one of Module's instance methods, so the decleared module Mod has a method include.
#Module is Class, and Class is a Module. Both of them has two set of methods: instance_methods and his owner methods.
instance method 'include' in Class is passed into Dog as regular method when declaration.
but when declear "dog = Dog.new", 'include' is not a instance method any more in Dog. So dog can't include.
def include_mod # not workable
include Mod
end
def self.include_mod #workable
include Mod
end
end
module Mod
def shat
puts "shat"
end
end
dog = Dog.new
dog.class.include_mod
puts Dog.instance_method :shat
dog.include_mod
#'include' is a method belonging to Module
#Class inherit Module, so Class can include
#And 'include' is one of Module's instance methods, so the decleared module Mod has a method include.
#Module is Class, and Class is a Module. Both of them has two set of methods: instance_methods and his owner methods.
instance method 'include' in Class is passed into Dog as regular method when declaration.
but when declear "dog = Dog.new", 'include' is not a instance method any more in Dog. So dog can't include.