lib/slop/option.rb in slop-1.4.0 vs lib/slop/option.rb in slop-1.4.1
- old
+ new
@@ -89,10 +89,12 @@
return if value.nil?
case @options[:as].to_s.downcase
when 'array'
value.split @delimiter, @limit
+ when 'range'
+ value_to_range value
when 'string'; value.to_s
when 'symbol'; value.to_s.to_sym
when 'integer'; value.to_s.to_i
when 'float'; value.to_s.to_f
else
@@ -138,8 +140,21 @@
# @return [String]
def inspect
"#<Slop::Option short_flag=#{@short_flag.inspect} " +
"long_flag=#{@long_flag.inspect} " +
"description=#{@description.inspect}>"
+ end
+
+ private
+
+ def value_to_range(value)
+ case value.to_s
+ when /\A(\d+?)(?:\.\.|-|,)(\d+)\z/
+ Integer($1) .. Integer($2)
+ when /\A(\d+?)\.\.\.(\d+)\z/
+ Integer($1) ... Integer($2)
+ else
+ value
+ end
end
end
end
\ No newline at end of file