Default arguments problem

Hi
How can I have a method with 3 arguments so that only second argument is
a default
argument for example:

def sum(p,q=2,r)
puts p+q+r
end

(I want to use from this method with only 2 arguments : first argument
and third argument )

On 2010-08-04 21:13:49 +0100, Amir E. said:

def sum(p,q=2,r)
puts p+q+r
end

Does the default arg have to be the second one? If not just move it to
the end of the args list.

def sum(p,r, q=2)
puts p+q+r
end

Amir E. wrote:

and third argument )
Only with ruby 1.9:

$ irb19

def sum(p,q=2,r)
puts p+q+r
end
=> nil

sum(1,2,3)
6
=> nil

sum(1,3)
6
=> nil