I used the following hook to check the module that makes the inclusion when I do include Foo
:
module Foo
def self.included(includer)
puts includer
end
end
Module#include
behaves differently in the module (where it is commonly used) against the top level. Inside a module self
is a module that is an instance Module
. When I invoke the include
module that performs the inclusion , thatself
:
module Bar
puts self
include Foo
end
At the top level of the ruby script, self
there is main
, which is an instance Object
. When I call include
at the top level, the module that performs the inclusion,, Object
is a class of thatself
:
puts self
include Foo
Can someone explain why?
; to_s
inspect
, main
, Object.new
to_s
inspect
, : #<Object:0x007fae0a87ac48>
.