diff --git a/lib/optparse.rb b/lib/optparse.rb index ade98708d6..11218fe940 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -1503,7 +1503,7 @@ XXX else raise ArgumentError, "argument pattern given twice" end - o.each {|pat, *v| pattern[pat] = v.fetch(0) {pat}} + o.each {|pat, *v| pattern[pat.to_s] = v.fetch(0) {pat}} when Module raise ArgumentError, "unsupported argument type: #{o}", ParseError.filter_backtrace(caller(4)) when *ArgumentStyle.keys diff --git a/test/optparse/test_placearg.rb b/test/optparse/test_placearg.rb index c6dc7abcf9..511541fecd 100644 --- a/test/optparse/test_placearg.rb +++ b/test/optparse/test_placearg.rb @@ -8,6 +8,7 @@ class TestOptionParserPlaceArg < TestOptionParser @opt.def_option("--option [VAL]") {|x| @flag = x} @opt.def_option("-T [level]", /^[0-4]$/, Integer) {|x| @topt = x} @opt.def_option("--enum [VAL]", [:Alpha, :Bravo, :Charlie]) {|x| @enum = x} + @opt.def_option("--integer [VAL]", [1, 2, 3]) {|x| @integer = x} @topt = nil @opt.def_option("-n") {} @opt.def_option("--regexp [REGEXP]", Regexp) {|x| @reopt = x} @@ -99,4 +100,9 @@ class TestOptionParserPlaceArg < TestOptionParser assert_equal([], no_error {@opt.parse!(%w"--enum=A")}) assert_equal(:Alpha, @enum) end + + def test_enum_conversion + assert_equal([], no_error {@opt.parse!(%w"--integer=1")}) + assert_equal(1, @integer) + end end