summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLee Jarvis <lee@jarvis.co>2011-04-14 21:07:43 +0100
committerLee Jarvis <lee@jarvis.co>2011-04-14 21:07:43 +0100
commitf45d5e64091b91ff8c07916698815838bfa6cd71 (patch)
treefd77e23057b54799ef438bca32b09c20cdf52ee0
parent84c12a31dc3479125f718725a183221a31a9ce5f (diff)
downloadslop-f45d5e64091b91ff8c07916698815838bfa6cd71.tar.gz
have :as => Range return an integer if the value is numeric only
-rw-r--r--lib/slop/option.rb2
-rw-r--r--test/option_test.rb2
2 files changed, 4 insertions, 0 deletions
diff --git a/lib/slop/option.rb b/lib/slop/option.rb
index e462366..7ace487 100644
--- a/lib/slop/option.rb
+++ b/lib/slop/option.rb
@@ -152,6 +152,8 @@ class Slop
Integer($1) .. Integer($2)
when /\A(\d+?)\.\.\.(\d+)\z/
Integer($1) ... Integer($2)
+ when /\A\d+\z/
+ Integer(value)
else
value
end
diff --git a/test/option_test.rb b/test/option_test.rb
index 68b4cf3..07168f5 100644
--- a/test/option_test.rb
+++ b/test/option_test.rb
@@ -74,8 +74,10 @@ class OptionTest < TestCase
assert_equal (1...10), option_value(%w/-r 1...10/, :r, true, :as => Range)
# default back to the string unless a regex is successful
+ # return value.to_i if the value is /\A\d+\z/
# maybe this should raise is Slop#strict?
assert_equal "1abc10", option_value(%w/-r 1abc10/, :r, true, :as => Range)
+ assert_equal 1, option_value(%w/-r 1/, :r, true, :as => Range)
end
test 'printing options' do