M
Michael Lesniak
Hello,
on my way through dynamic method creation another question arose:
--- snip ---
def gen_times(factor)
return Proc.new {|n| n*factor }
end
times3 = gen_times(3)
times3.call(12)
--- snap ---
This example from the ruby-book creates a function on the fly which I
quite what I searched for. From my little scheme background I supposed
that I can directly bind the return value of gen_times to a variable
which is then equal to a method call. But, as exemplified above, I have
to go through call(...). Is there any way to convert a Proc-object to a
normal method, e.g. I would only have to do
new_times3 = gen_times(3).magic_call
and could then just write
new_times3(12)
Thanks for helping,
Michael
on my way through dynamic method creation another question arose:
--- snip ---
def gen_times(factor)
return Proc.new {|n| n*factor }
end
times3 = gen_times(3)
times3.call(12)
--- snap ---
This example from the ruby-book creates a function on the fly which I
quite what I searched for. From my little scheme background I supposed
that I can directly bind the return value of gen_times to a variable
which is then equal to a method call. But, as exemplified above, I have
to go through call(...). Is there any way to convert a Proc-object to a
normal method, e.g. I would only have to do
new_times3 = gen_times(3).magic_call
and could then just write
new_times3(12)
Thanks for helping,
Michael