Skip to content

Commit 389663a

Browse files
committed
allows negative numeric arguments
1 parent 942bbfe commit 389663a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/thor/parser/arguments.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Thor
22
class Arguments #:nodoc: # rubocop:disable ClassLength
3-
NUMERIC = /(\d*\.\d+|\d+)/
3+
NUMERIC = /[-+]{0,1}(\d*\.\d+|\d+)/
44

55
# Receives an array of args and returns two arrays, one with arguments
66
# and one with switches.

spec/parser/arguments_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def parse(*args)
2121
create :string => nil, :numeric => nil
2222
expect(parse("name", "13")["string"]).to eq("name")
2323
expect(parse("name", "13")["numeric"]).to eq(13)
24+
expect(parse("name", "+13")["numeric"]).to eq(13)
25+
expect(parse("name", "+13.3")["numeric"]).to eq(13.3)
26+
expect(parse("name", "-13")["numeric"]).to eq(-13)
27+
expect(parse("name", "-13.3")["numeric"]).to eq(-13.3)
2428
end
2529

2630
it "accepts hashes" do

0 commit comments

Comments
 (0)