On 12/4/06, Yang Bob <bob.yang.dev / gmail.com> wrote:
> But how about overloading by parameter numbers. such as:
> class FooClass {
>    def foo(first){ }
>    def foo(first, second) { }
> }
>
> does ruby support this ? if can not, how can we workaround this?
>
> thanks
>

There's also this one:

def foo opts={}
  if opts[:some_parameter]
    do_something_with_parameter
  end

  if opts[:some_other_parameter]
    do_something_with_other_parameter
  end
end

foo :some_parameter=>123, :some_other_parameter=>'abc'

This is used as a substitute for 'true' named parameters. It is mostly
useful if you need to take a moderate number of entirely optional
parameters.

Cheers,
Max