I want to call instance_eval
on this class:
class A
attr_reader :att
end
passing this method b
:
class B
def b(*args)
att
end
end
but this is happening:
a = A.new
bb = B.new
a.instance_eval(&bb.method(:b)) # NameError: undefined local variable or method `att' for #<B:0x007fb39ad0d568>
When b
is a block it works, but b
as a method isn't working. How can I make it work?
This answer does not use a real method as asked, but I didn't need to return a
Proc
or changeA
. This is a DSL,def_b
should have a meaningful name to the domain, likeconfigure
, and it is more likely to be defined in a module or base class.And it accepts multiple definitions. It could be made accept only a single definition like this: