I would like to write an includable method tracker, which logs about
added
methods to a class.
module MethodTracker
def self.method_added(method_name)
puts “Tracking #{method_name}”
end
end
class Factory
include MethodTracker
def build
end
end
This is my code, however when the Factory
class is defined there is no
message shown. Can you give me a hint?
Kenny M.
I make Software.
www.kennymeyer.net | +(595) 982 52 74 11
You don’t have anything that initializes the module, if you want it to
be “auto triggered” then create an initialize method in MethodTracker
rough example:
module MethodTracker
def initialize(method_name=“test”)
puts “Tracking #{method_name}”
end
end
class Factory
include MethodTracker
def build
end
end
x = Factory.new;
puts x.build
On Jul 31, 2013, at 13:44 , Kenny M. [email protected] wrote:
def build
end
end
This is my code, however when the Factory
class is defined there is no message
shown. Can you give me a hint?
method_added is a class method, so you need to extend Factory, not
include.
module MethodTracker
def method_added(method_name)
puts “Tracking #{method_name}”
end
end
class Factory
extend MethodTracker
def build
end
end
Duh… thanks, for pointing out this small detail.
Kenny M.
I make Software.
www.kennymeyer.net | +(595) 982 52 74 11
On Jul 31, 2013, at 14:05 , Max D. [email protected] wrote:
You don’t have anything that initializes the module, if you want it to be “auto
triggered” then create an initialize method in MethodTracker
rough example:
too rough