"self.included?" in Ruby -
in following code,
module test @connection = nil def self.included?(base) @connection = base end def print puts @connection end end class moduletest include test end m = moduletest.new m.print why @connection nil when printing?
when run print, prints instance variable @connection of instance of moduletest. have 2 other places in code referring @connection, point instance variable @connection of instance moduletest of class class, , different thing.
furthermore, latter @connection (the 1 moduletest class) not value base until included?.
the instance variable instance of moduletest created initialized nil default when called puts within print.
Comments
Post a Comment