Do you know how to define @@method_names class variable so that both my_macro and invoke_methods can use it as intended? Thank you!
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
@@method_names = []before@@method_names << method_name@@method_names = [] unless @@method_names; @@method_names << method_namebut gotNameError: uninitialized class variable @@method_names in MyModule::ClassMethods@@method_names = @@method_names || []