Module: NumericHelper
- Included in:
- Numeric
- Defined in:
- lib/rubyhelper/numeric.rb
Instance Method Summary collapse
-
#max(maximum_value) ⇒ Numeric
Get the self value or maximum_value if lesser than self.
-
#max!(maximum_value) ⇒ Numeric
see #max.
-
#min(minimum_value) ⇒ Numeric
Get the self value or minimum_value if greater than self.
-
#min!(minimum_value) ⇒ Numeric
see #min.
-
#odd? ⇒ true or false
return true if odd you can see also #peer?.
-
#peer? ⇒ true or false
return true if peer you can see also #odd?.
-
#sign(plus = "+", less = "-") ⇒ Object
get - or + function of the sign of the integer.
Instance Method Details
#max(maximum_value) ⇒ Numeric
Get the self value or maximum_value if lesser than self
35 36 37 38 |
# File 'lib/rubyhelper/numeric.rb', line 35 def max(maximum_value) raise ArgumentError unless maximum_value.is_a? Numeric return self <= maximum_value ? self : maximum_value end |
#max!(maximum_value) ⇒ Numeric
see #max
43 44 45 |
# File 'lib/rubyhelper/numeric.rb', line 43 def max!(maximum_value) return self.replace(self.min(maximum_value)) end |
#min(minimum_value) ⇒ Numeric
Get the self value or minimum_value if greater than self
19 20 21 22 |
# File 'lib/rubyhelper/numeric.rb', line 19 def min(minimum_value) raise ArgumentError unless minimum_value.is_a? Numeric return self >= minimum_value ? self : minimum_value end |
#min!(minimum_value) ⇒ Numeric
see #min
27 28 29 |
# File 'lib/rubyhelper/numeric.rb', line 27 def min!(minimum_value) return self.replace(self.min(minimum_value)) end |
#odd? ⇒ true or false
return true if odd you can see also #peer?
59 60 61 |
# File 'lib/rubyhelper/numeric.rb', line 59 def odd? not peer? end |
#peer? ⇒ true or false
return true if peer you can see also #odd?
51 52 53 |
# File 'lib/rubyhelper/numeric.rb', line 51 def peer? return (self % 2).zero? ? true : false end |
#sign(plus = "+", less = "-") ⇒ Object
get - or + function of the sign of the integer
11 12 13 |
# File 'lib/rubyhelper/numeric.rb', line 11 def sign(plus="+", less="-") return (self < 0) ? (less) : (plus) end |