summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md7
-rw-r--r--lib/slop/parser.rb1
-rw-r--r--lib/slop/types.rb2
-rw-r--r--test/types_test.rb6
4 files changed, 13 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4fe6bd5..0b029a2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,13 @@
Changelog
=========
+Unreleased
+----------
+
+Features:
+ * Add support for prefixing integer values with `+` character
+ [#243] (Juha Ylitalo)
+
v4.7.0 (2019-06-29)
-------------------
diff --git a/lib/slop/parser.rb b/lib/slop/parser.rb
index c6462ea..00b7e33 100644
--- a/lib/slop/parser.rb
+++ b/lib/slop/parser.rb
@@ -52,7 +52,6 @@ module Slop
# support `foo=bar`
orig_flag = flag.dup
- orig_arg = arg
if match = flag.match(/([^=]+)=([^=]+)/)
flag, arg = match.captures
end
diff --git a/lib/slop/types.rb b/lib/slop/types.rb
index b7e41c8..4cd6136 100644
--- a/lib/slop/types.rb
+++ b/lib/slop/types.rb
@@ -44,7 +44,7 @@ module Slop
# Cast the option argument to an Integer.
class IntegerOption < Option
def call(value)
- value =~ /\A-?\d+\z/ && value.to_i
+ value =~ /\A[+-]?\d+\z/ && value.to_i
end
end
IntOption = IntegerOption
diff --git a/test/types_test.rb b/test/types_test.rb
index c1aabaa..f6b928e 100644
--- a/test/types_test.rb
+++ b/test/types_test.rb
@@ -32,11 +32,15 @@ describe Slop::IntegerOption do
before do
@options = Slop::Options.new
@age = @options.integer "--age"
- @result = @options.parse %w(--age 20)
+ @minus = @options.integer "--minus"
+ @plus = @options.integer "--plus"
+ @result = @options.parse %w(--age 20 --minus -10 --plus +30)
end
it "returns the value as an integer" do
assert_equal 20, @result[:age]
+ assert_equal -10, @result[:minus]
+ assert_equal 30, @result[:plus]
end
it "returns nil for non-numbers by default" do