Daniel Sheppard
3/23/2007 1:27:00 AM
> harp:~ > cat a.rb
> def myfunc *a, &b
> x = a.shift || b.call
> Math.sin(x) * Math.cos(x) * Math.exp(x)
> end
That's got the same problem - rand will only be evaluated once, what you
were no doubt after is:
def myfunc *a, &b
b ||= proc { a.first }
Math.sin(b.call) * Math.cos(b.call) * Math.exp(b.call)
end
But the point remains, anything macros do, functions or metaprogramming
do better.
Dan.