From cf008e6d51993e5747eff0d12756fffb6b97ba6d Mon Sep 17 00:00:00 2001 From: Alexander Staubo Date: Fri, 11 Jul 2014 23:46:02 -0400 Subject: [PATCH] Use option object as key in the command's @map hash, to avoid hash collisions clobbering different options. At the same time, fix Option#hash to use XOR operator rather than AND, to avoid hash collisions. --- lib/mercenary/command.rb | 4 ++-- lib/mercenary/option.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/mercenary/command.rb b/lib/mercenary/command.rb index 23b9dc4..0bcc4dd 100644 --- a/lib/mercenary/command.rb +++ b/lib/mercenary/command.rb @@ -92,7 +92,7 @@ def default_command(command_name = nil) def option(sym, *options) new_option = Option.new(sym, options) @options << new_option - @map[new_option.hash] = sym + @map[new_option] = sym end # Public: Adds a subcommand @@ -178,7 +178,7 @@ def go(argv, opts, config) def process_options(opts, config) options.each do |option| opts.on(*option.for_option_parser) do |x| - config[map[option.hash]] = x + config[map[option]] = x end end end diff --git a/lib/mercenary/option.rb b/lib/mercenary/option.rb index d59aa46..56a49b6 100644 --- a/lib/mercenary/option.rb +++ b/lib/mercenary/option.rb @@ -61,7 +61,7 @@ def formatted_switches def hash instance_variables.map do |var| instance_variable_get(var).hash - end.reduce(:&) + end.reduce(:^) end # Public: Check equivalence of two Options based on equivalence of their