From: Joel VanderWerf Date: 2006-12-21T09:54:21+09:00 Subject: Re: Discovering the number of return arguments requested. Brad Phelan wrote: > 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. 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 -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407