In addition to caspers answer:
You may use a splash parameter and check, if the last parameter is a hash.
Then you take the hash as settings.
A code example:
def test(id, *ary )
if ary.last.is_a?(Hash)
hash_params = ary.pop
else
hash_params = {}
end
# Do stuff here
puts "#{id}:\t#{ary.inspect}\t#{hash_params.inspect}"
end
test(1, :a, :b )
test(2, :a, :b, :p1 => 1, :p2 => 2 )
test(3, :a, :p1 => 1, :p2 => 2 )
Result is:
1: [:a, :b] {}
2: [:a, :b] {:p1=>1, :p2=>2}
3: [:a] {:p1=>1, :p2=>2}
This will make problems, if your array-parameter should contain a hash at last position.
test(5, :a, {:p1 => 1, :p2 => 2} )
test(6, :a, {:p1 => 1, :p2 => 2}, {} )
Result:
5: [:a] {:p1=>1, :p2=>2}
6: [:a, {:p1=>1, :p2=>2}] {}