Class: Integer
Class Method Summary collapse
-
.to_converter_proc ⇒ Object
Returns a Proc that converts to Integer.
Class Method Details
.to_converter_proc ⇒ Object
Returns a Proc that converts to Integer
Integer.to_converter_proc.call(1) # => 1
Integer.to_converter_proc.call(1.9) # => 2
Integer.to_converter_proc.call('1.9') # => 2
Integer.to_converter_proc.call('abc') # ArgumentError: invalid value for Float(): "abc"
See Conversion.converter, Object#convert_to
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/conversion/class_decoration.rb', line 54 def to_converter_proc proc do |value| if value.is_a?(Float) value.round else begin Integer(value) rescue Exception Float(value).round end end end end |