Module: NumericHelper
- Included in:
- Numeric
- Defined in:
- lib/rubyhelper/numerichelper.rb
Instance Method Summary collapse
-
#max(maximum_value) ⇒ Object
Errors ArgumentError : if the passed value is not an integer Returns value: (Numeric) self if self <= max else max.
- #max!(maximum_value) ⇒ Object
-
#min(minimum_value) ⇒ Object
Errors ArgumentError : if the passed value is not an integer Returns value: (Numeric) self if self >= min else min.
- #min!(minimum_value) ⇒ Object
-
#sign ⇒ Object
get - or + function of the sign of the integer.
Instance Method Details
#max(maximum_value) ⇒ Object
Errors ArgumentError : if the passed value is not an integer Returns value: (Numeric) self if self <= max else max
27 28 29 30 |
# File 'lib/rubyhelper/numerichelper.rb', line 27 def max(maximum_value) raise ArgumentError unless maximum_value.is_a? Numeric return self <= maximum_value ? self : maximum_value end |
#max!(maximum_value) ⇒ Object
31 32 33 |
# File 'lib/rubyhelper/numerichelper.rb', line 31 def max!(maximum_value) return self.replace(self.min(maximum_value)) end |
#min(minimum_value) ⇒ Object
Errors ArgumentError : if the passed value is not an integer Returns value: (Numeric) self if self >= min else min
15 16 17 18 |
# File 'lib/rubyhelper/numerichelper.rb', line 15 def min(minimum_value) raise ArgumentError unless minimum_value.is_a? Numeric return self >= minimum_value ? self : minimum_value end |
#min!(minimum_value) ⇒ Object
19 20 21 |
# File 'lib/rubyhelper/numerichelper.rb', line 19 def min!(minimum_value) return self.replace(self.min(minimum_value)) end |
#sign ⇒ Object
get - or + function of the sign of the integer
7 8 9 |
# File 'lib/rubyhelper/numerichelper.rb', line 7 def sign return (self < 0) ? ("-") : ("+") end |