Man, I'm peeling the layers of the onion today, anyway here's the code
class MyClass
def initialize(dynamic_methods)
@arr = Array.new(dynamic_methods)
@arr.each { |m|
self.class.class_eval do
define_method(m) do
"<#{yield self if block_given?}>"
end
end
}
end
end
tmp = MyClass.new ['method1', 'method2', 'method3']
tmp.method1 do |t|
"here"
end
My problem is that I'm trying to access "here" within define_method(m) when the method is being executed, not when created. The current statement "<#{yield self if block_given?}>" doesn't give me that. And in case you are wondering, I have to keep this part of the code as is but I can make all the changes I want to MyClass.
tmp = MyClass.new ['method1', 'method2', 'method3']
tmp.method1 do |t|
"here"
end
Can anyone help with the syntax? Thanks in advance for your help.
UPDATE: See below for my answer.