From: Woody Peterson Date: 2008-09-08T17:58:28+09:00 Subject: Hash auto-true ({:a} == {:a => true}) 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. Example: method(:flag, :another, :config => "/etc/whatever") For some of the functionality I colud use *args and check args.include?(:foo), but then I couldn't pass in key-value pairs easily. The closest way would be to use *args to pass in things of the form method(:flag, [:config, "/etc/whatever"]), then use args.include?(:flag) for flags and args.assoc(:config)[1] for value-based options. Example: method(:flag, [:config, "/etc/whatever"]) ex. code: if args.include?(:flag) do; stuff; end if args.assoc(:config) do; @config = args.assoc(:config)[1]; end I'd have to make the args.assoc logic prettier with a helper method to set up default values, but that's the basics of it. Much easier/prettier if I could modify Hash to auto-assign empty keys to true. Note that there's a way to set the default value for empty keys from nil to another value (and even a proc), but this wouldn't be what I want. I want empty keys to be nil, and specified lone keys set to true. Thoughts? Anybody else think this would be really handy, or am I missing something? -- Posted via http://www.ruby-forum.com/.