Class: Slop::IntegerOption

Inherits:
Option
  • Object
show all
Defined in:
lib/slop/types.rb

Overview

Cast the option argument to an Integer.

Constant Summary collapse

INT_STRING_REGEXP =
/\A[+-]?\d+\z/.freeze

Constants inherited from Option

Option::DEFAULT_CONFIG

Instance Attribute Summary

Attributes inherited from Option

#block, #config, #count, #desc, #flags, #value

Instance Method Summary collapse

Methods inherited from Option

#default_value, #ensure_call, #expects_argument?, #finish, #flag, #help?, #initialize, #key, #null?, #required?, #reset, #suppress_errors?, #tail, #tail?, #to_s, #underscore_flags?, #validate_type?

Constructor Details

This class inherits a constructor from Slop::Option

Instance Method Details

#call(value) ⇒ Object



73
74
75
# File 'lib/slop/types.rb', line 73

def call(value)
  value.to_i
end

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/slop/types.rb', line 69

def valid?(value)
  value =~ INT_STRING_REGEXP
end