module NumericHelper
encoding: utf-8
Public Instance Methods
max(maximum_value)
click to toggle source
Get the self value or maximum_value if lesser than self
@raise [ArgumentError] if the passed value is not an integer @return [Numeric] self if self <= max else max
# 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)
click to toggle source
see {#max}
@return [Numeric]
# File lib/rubyhelper/numeric.rb, line 43 def max!(maximum_value) return self.replace(self.min(maximum_value)) end
min(minimum_value)
click to toggle source
Get the self value or minimum_value if greater than self
@raise [ArgumentError] if the passed value is not an integer @return [Numeric] self if self >= min else min
# 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)
click to toggle source
see {#min}
@return [Numeric]
# File lib/rubyhelper/numeric.rb, line 27 def min!(minimum_value) return self.replace(self.min(minimum_value)) end
odd?()
click to toggle source
return true if odd you can see also {#peer?}
@return [true or false]
# File lib/rubyhelper/numeric.rb, line 59 def odd? not peer? end
peer?()
click to toggle source
return true if peer you can see also {#odd?}
@return [true or false]
# File lib/rubyhelper/numeric.rb, line 51 def peer? return (self % 2).zero? ? true : false end
sign(plus="+", less="-")
click to toggle source
get - or + function of the sign of the integer
@param plus [Object] a value if self >= 0 @param less [Object] a value if self < 0 @return [Object] the param plus or less if self >= 0 or < 0
# File lib/rubyhelper/numeric.rb, line 11 def sign(plus="+", less="-") return (self < 0) ? (less) : (plus) end