我想知道在 Ruby 中调用了多少返回参数 method_missing 。我想根据它应该产生多少返回参数来改变函数的行为。我正在寻找与nargout
Matlab 等效的东西。本例中的 XXX:
class Test
def method_missing(method_id, *args)
n_return_arguments = XXX
if n_return_arguments == 1
return 5
else
return 10, 20
end
end
end
t = Test.new.missing_method # t should now be 5
t1, t2 = Test.new.missing_method # t1 should now be 10 and t2 should now be 20