From 6995484ee3a4a505c1c8705709f8dc00899013b3 Mon Sep 17 00:00:00 2001 From: Hansuk Date: Thu, 16 Jan 2020 00:38:27 +0900 Subject: 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 --- lib/slop/types.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib') 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 -- cgit v1.2.1