From: Alexandre Rosenfeld Date: 2007-04-08T04:32:38+09:00 Subject: Re: Method constant arguments Thank you all for the answers. I really liked the solution below. It can handle a lot of the things I want to do. I can set overwrite to true as default for instance. I remember keyword arguments when I began learning Python and I liked it. Then I found Ruby and I couldnt go back ;) It would be a nice thing to have it in Ruby. Thanks a lot. Gavin Kistner wrote: > On Apr 6, 11:47 pm, Alexandre Rosenfeld wrote: >> I have tried array arguments and hashes, but I didn't like those >> solutions. What would be the recommended way to do that in Ruby? > > Here's one way: > > def dosomehomework( directory, options={} ) > if options[:overwrite] then > ... > end > > dosomehomework '/', :use_id_as_filename=>true, :overwrite=>false > > You lose the self-documentating nature of the method arguments, but > gain clarity in the method call as well as order-independance. > > Rumor has it Ruby 2.0 will have keyword arguments; I'm not sure what > the current proposal is, but iirc you'll have the best of both worlds > there. -- Posted via http://www.ruby-forum.com/.