Module: Types::Decimal

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

Overview

Represents a decimal type using BigDecimal.

“‘ruby type = Types::Decimal type.parse(“3.14”) # => #<BigDecimal …> “`

Class Method Summary collapse

Methods included from Generic

composite?, to_rbs, to_s, |

Class Method Details

.parse(input) ⇒ Object

Parses the input as a BigDecimal.



23
24
25
26
27
28
29
30
# File 'lib/types/decimal.rb', line 23

def self.parse(input)
	case input
	when ::Float
		Kernel.BigDecimal(input, ::Float::DIG+1)
	else
		Kernel.BigDecimal(input)
	end
end

.resolveObject

Resolves to the actual Ruby BigDecimal class.



34
35
36
# File 'lib/types/decimal.rb', line 34

def self.resolve
	::BigDecimal
end