Class: Float
Class Method Summary collapse
-
.from_user_input(value) ⇒ Object
All characters must be numbers, except there can be up to one decimal and a negative sign at the front.
Instance Method Summary collapse
-
#from_user_input(value) ⇒ Object
instance form does a straight comparison of value.to_f with self.
Class Method Details
.from_user_input(value) ⇒ Object
All characters must be numbers, except there can be up to one decimal and a negative sign at the front
93 94 95 96 97 98 99 |
# File 'lib/user_input.rb', line 93 def Float.from_user_input(value) if (value.kind_of?(Float) || /^\s*-?[0-9]*(\.[0-9]+)?\s*$/ =~ value.to_s) return value.to_f else return nil end end |
Instance Method Details
#from_user_input(value) ⇒ Object
instance form does a straight comparison of value.to_f with self.
102 103 104 105 106 107 108 |
# File 'lib/user_input.rb', line 102 def from_user_input(value) if (self == value.to_f) return value.to_f else return nil end end |