B
Brian Schröder
Please help me to wrap my mind around this. I want to achieve the following=
:
class A
def self.def_me(cmd, &block)
eval %(
def #{cmd}()
do things
# CALL BLOCK
end
)
end
def_me("foo") do
# access instance of A
end
end
A.new.foo
and have the block from the dynamically created method foo be
evaluated in the binding of the instance of A.
I'm sure this is possible, but I've never really grocked eval,
instance_eval and class_eval.
best regards,
Brian
:
class A
def self.def_me(cmd, &block)
eval %(
def #{cmd}()
do things
# CALL BLOCK
end
)
end
def_me("foo") do
# access instance of A
end
end
A.new.foo
and have the block from the dynamically created method foo be
evaluated in the binding of the instance of A.
I'm sure this is possible, but I've never really grocked eval,
instance_eval and class_eval.
best regards,
Brian