I am not sure this is possible. Consider the following:
class Test
def method(a,b=1)
local_variables.each do |var|
puts "Setting #{var} to #{eval var.to_s}"
end
end
end
And then try to call method
on an instance of Test
:
?> t.method(1)
Setting a to 1
Setting b to 1
=> [:a, :b]
?> t.method(1,2)
Setting a to 1
Setting b to 2
=> [:a, :b]
?> t.method(1,1)
Setting a to 1
Setting b to 1
=> [:a, :b]
Those do not distinguish how the method was called.
So I would suggest @sawa's approach mixed with the following:
raise ArgumentError, "Too many arguments" if args.length > 2
since you seem to want to limit the parameters to 2 and @sawa's approach allows for an undefined number.
This is an unorthodox approach to an unorthodox requirement, so just make sure the clients of your method are aware of how the API works.