Well, the beauty of Ruby is that you can change that as you see fit!
But ther seems little reason for having a return value that matches the value you want to output if you are outputting the value anyway. The value hasn't changed and is already located in it's own little object. Seems in Ruby it's easy enough to pass that value to output and to anywhere else you need it/ want it.
It's made with C, but I don't think it works like C.
Oh yes, lots of times. When I'm debugging code I sometimes want to see
the state of an object, but I don't want to mess with the execution.
With complex statements this isn't always straight forward. For
instance,
def foo(x)
bar(baz(x))
end
If I want to see the result of baz(x), I'd need to change it to
something like:
Here is a version that also handles multiple parameters required for
correct automatic array building like in "a,b,c=p(1,2,3)":
module Kernel
alias_method :old_p,
def p *args
old_p(*args)
args.length>1 ? args : args[0]
end
end
If multiple parameters are given, let's return the array we already
have. Don't return an array if it's just one parameter (the usual
case). Note that the case of no parameter results in nil returned
(certainly).