=20
I think you want to dynamically define one method from within another.
Try this:
=20
def make_pay_loan
def pay_loan
puts 'paid'
end
end
But there is nothing dynamic about that solution. All you're doing is =
defining a def expression inside of another which will get defined the =
first time (and every time for that matter) make_pay_loan gets called. =
pay_loan is entirely static and has no ability to be dynamic in any way.
You'll want to use define_method or eval in order to actually be =
dynamic.
% echo "def make_pay_loan
def pay_loan
puts 'paid'
end
end
" | parse_tree_show
s
defn, :make_pay_loan,
s
args),
s
scope,
s
block,
s
defn,
ay_loan,
s
args),
s
scope,
s
block, s
call, nil,
uts, s
arglist, s
str, "paid")))))))))
Depending on how the OP means "activate", it could be as simple as =
calling public on the method to make it visible, or as complex as =
defining a dynamic method with define_method and using the closure to =
capture the dynamic values passed in to make_pay_loan.=