Module: Types::Numeric

Extended by:
Generic
Defined in:
lib/types/numeric.rb

Overview

Represents a numeric type (integer or float).

“‘ruby type = Types::Numeric type.parse(“42”) # => 42 type.parse(“3.14”) # => 3.14 “`

Class Method Summary collapse

Methods included from Generic

composite?, to_rbs, to_s, |

Class Method Details

.parse(input) ⇒ Object

Parses the input as a numeric value (integer or float).



22
23
24
25
26
27
28
# File 'lib/types/numeric.rb', line 22

def self.parse(input)
	case input
	when Numeric then input
	when /\./ then Float(input)
	else Integer(input)
	end
end