On Sat, Jan 24, 2004 at 02:03:52PM +0900, nobu.nokada / softhome.net wrote:
> def my_method(foo = (defaulted = 'bar'))
>   if defaulted
>     puts "warning: default value #{foo} being used for 'foo'"
>   end
> end

I like that.  Nice and simple, and easily extended:

def my_method(foo = (default_foo = 'foo'), bar = (default_bar = 'bar'))
    warn "warning: default value #{foo} being used for foo" if default_foo;
    warn "warning: default value #{bar} being used for bar" if default_bar;
    . . . 
end

or, to get a little fancier:

def my_method(foo = ((defaulted||={})[:foo] = 'foo'), 
              bar = ((defaulted||={})[:bar] = 'bar'))
    if defaulted
        defaulted.each do
            |arg, val|
            warn "warning: default value `#{val}' being used for `#{arg}'"
        end
    end
end

irb(main):001:0> my_method
warning: default value `bar' being used for `bar'
warning: default value `foo' being used for `foo'
irb(main):002:0> my_method(1)
warning: default value `bar' being used for `bar'
irb(main):003:0> my_method(1,2)
irb(main):004:0>