From: James Coglan Date: 2008-09-08T18:17:26+09:00 Subject: Re: Hash auto-true ({:a} == {:a => true}) ------=_Part_3363_8036674.1220865817960 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 2008/9/8 Woody Peterson > I have a unix-inspired desire to pass arguments to a method where some > are toggle flags and some are values, aka "bash$ method --flag > --config=/etc/method". I can think of a few ways to do it that are > close, but if I had a hash that initiated value-less keys to true, I > would have it. If you make the restriction that flags always come first you could do something like this: def my_method(arg1, arg2, *args) options = (Hash === args.last) ? args.pop : {} puts args.inspect puts options.inspect end my_method('foo', 'bar', :flag, :value => 'something') [:flag] {:value=>"something"} my_method('foo', 'bar', :flag) [:flag] {} my_method('foo', 'bar', :value => 'something') [] {:value=>"something"} Then you can check for flags using args.include?(:foo), or you could loop over them and set them to true in the hash: args.each { |key| options[key] = true } ------=_Part_3363_8036674.1220865817960--