I have the following program.
module C
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def test_for
class_eval <<-DEFINECLASSMETHODS
def self.my_method(param_a)
puts "SELF is: #{self.inspect}"
puts param_a
puts "#{param_a}"
end
DEFINECLASSMETHODS
end
end
end
class A
include C
end
class B < A
test_for
end
when I run B.new.my_method("aaa")
, I got this error
NameError: undefined local variable or method `param_a' for B:Class
I am quite confused.
I define param_a as a local variable in class method my_method,
puts param_a
runs good, and will output the "aaa".
however,
puts "#{param_a}"
output that error.
why?
Can anyone explain this?