summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHansuk <flavono123@gmail.com>2020-01-16 00:38:27 +0900
committerHansuk <flavono123@gmail.com>2020-01-16 00:38:27 +0900
commit6995484ee3a4a505c1c8705709f8dc00899013b3 (patch)
tree036e2c926399171f36a0131f83ca82a1b4616b8b /lib
parent909403b32065e467487e7810bf2d535504182df5 (diff)
downloadslop-6995484ee3a4a505c1c8705709f8dc00899013b3.tar.gz
support scientific nations for float options
- reference: https://stackoverflow.com/questions/638565/parsing-scientific-notation-sensibly - remove the todo comment(no idea for etc) Signed-off-by: Hansuk <flavono123@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/slop/types.rb3
1 files changed, 1 insertions, 2 deletions
diff --git a/lib/slop/types.rb b/lib/slop/types.rb
index 07d7e62..c1055ea 100644
--- a/lib/slop/types.rb
+++ b/lib/slop/types.rb
@@ -52,8 +52,7 @@ module Slop
# Cast the option argument to a Float.
class FloatOption < Option
def call(value)
- # TODO: scientific notation, etc.
- value =~ /\A[+-]?\d*\.*\d+\z/ && value.to_f
+ value =~ /\A[+-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+-]?\d+)?\z/ && value.to_f
end
end