Consider the following piece of code:
f = Proc.new {|*args| g(*args)}
f is a proc object which, when called, basically behaves like g (the
only difference being the fact that one additional function call is
executed, when g is called “via f”.
Now two questions about it:
-
Is there a (syntactically) easier way to write this? I first thought
that
f = &:g
would be valid, but it isn’t. -
Is there a way in Ruby to define a “function pointer” f (using C
terminology here), so that calling f(…) is absolutely equivalent to
calling g(…)? I do NOT mean creating an alias to the function.