"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

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -