Discovering the number of return arguments requested

Is it possible ( and I think not ) that you can discover if any return
arguments are requested when a method is called.

Eg:

def foo
if nargout == 1
“bar”
end
end

a = foo # nargout == 1
foo # nargout == 0

This would be useful in certain patterns where you only want to
create a return value and consequently a new object if it is
actually required.

Brad P. wrote:

a = foo # nargout == 1
foo # nargout == 0

This would be useful in certain patterns where you only want to
create a return value and consequently a new object if it is
actually required.

One option is yield:

def foo
yield “bar” if block_given?
end

a = nil

foo {|x| a=x}
#or:
#foo {|a|} # this doesn’t work in 1.9 IIRC