Знаете ли вы, как определить переменную класса @@method_names
, чтобы и my_macro
, и invoke_methods
могли использовать ее по назначению? Спасибо!
module MyModule
module ClassMethods
def my_macro method_name, options = { }
define_method method_name do
puts "defining #{method_name} with #{options}"
end
@@method_names << method_name
end
end
def invoke_methods
@@method_names.each { |method_name| send method_name }
end
def self.included includer
includer.extend ClassMethods
end
end
class MyClass
include MyModule
my_macro :method_foo, :bar => 5
my_macro :method_baz, :wee => [3,4]
end
MyClass.new.invoke_methods