If I have the following Ruby code:
def result(b=25)
puts b
end
then I can simply call result, and 25 will be output. So far, no problem.
But I’d like to call it from another method, like this:
def outer(a,b)
#...do some stuff with a...
result(b)
end
and I’d like outer(1,5) to output 5, but outer(1) to simply output 25. In effect, I want to pass “undefined” through to the result method.
Is there any way I can do this? (I can’t simply use def outer(a,b=25), sadly, because the default value for b is actually an instance variable of the class in which result is a method.)
what about this:
That will call result(b) if b is not nil and result() if b is nil