How do I pass the parameter name in the following case..the name is being is evaluated before being passed to class_eval
class Foo
end
Foo.class_eval %Q{
def hello(name)
p "hello #{name}"
end
}
Sorry about not giving the entire scenario…
I just wanted to add a instance method dynamically to a class and that method should be able to take arguments…
the above code would not compile complaining that the name is not defined as local variable when executing in irb..
Thanks
The other answers are the “right” answer, but you could also just skip interpolating inside the
pcall:I thought you wanted to change the actual parameter name (possibly useful for completion or when using Pry on dynamic methods), here assuming it’s in a global, but could also be passed into a method doing the
class_eval: