2008/3/12, Max Williams <toastkid.williams / gmail.com>: > > > > > There's also no such thing as a hash key that isn't part of a hash. It > > sounds like what you want to do is pass multiple objects to your > > method and create a hash from them inside the method. > > > > > > David > > Hi David > > I know what you're saying, it is a bit clumsy. Pardon me, but it seems David's words did not sink in since you are still talking about a Hash key where you mean "symbol". > Where i'm coming from is that i often use a lot of options that are set > to true by the user of the method if they want to use them, which does > work nicely due to options[:foo] evaluating to nil if the user didn't > set it, allowing me to have tests like > if options[:foo] #missing key equivalent to :foo => false > do_extra_stuff > end > > I just thought it would be even nicer to have the user just be able to > pass the hash key, rather than have to keep adding "=> true". So the > presence of a hash key acts like a switch which i can test with > > if options.has_key? :foo > do_extra_stuff > end > > I thought i'd seen this functionality in rails, where we can pass just a > hash key without bothering to set it, if we want to switch something on > or off. If you need a set of boolean flags then you can just use an array irb(main):008:0> def x(*opts) irb(main):009:1> settings = opts.inject({}){|h,o| h[o]=true;h} irb(main):010:1> end => nil irb(main):011:0> x(:foo, :lazy) => {:lazy=>true, :foo=>true} irb(main):012:0> Kind regards robert -- use.inject do |as, often| as.you_can - without end