Class: Numeric
- Defined in:
- lib/nano/numeric/pred.rb,
lib/nano/numeric/succ.rb,
lib/nano/numeric/to_b.rb,
lib/nano/float/round_at.rb,
lib/nano/float/round_to.rb,
lib/nano/float/approx%3F.rb,
lib/nano/float/round_off.rb,
lib/nano/numeric/distance.rb,
lib/nano/numeric/ceil_multiple.rb
Instance Method Summary collapse
-
#approx?(*args) ⇒ Boolean
To properly support Float#approx?, Numeric must also be augmented.
-
#ceil_multiple(multiple) ⇒ Object
Returns the multiple ceil of a number.
-
#distance(other) ⇒ Object
Returns the distance between self an another value.
-
#pred(n = nil) ⇒ Object
Provides #pred as the opposite of #succ.
-
#round_at(*args) ⇒ Object
To properly support Float’s rounding methods, Numeric must also be augmented.
-
#round_to(*args) ⇒ Object
To properly support Float’s rounding methods, Numeric must also be augmented.
-
#succ(n = nil) ⇒ Object
Allows #succ to take n increments.
-
#to_b ⇒ Object
Provides a boolean interpretation of self.
Instance Method Details
#approx?(*args) ⇒ Boolean
To properly support Float#approx?, Numeric must also be augmented.
16 17 18 |
# File 'lib/nano/float/approx%3F.rb', line 16 def approx?(*args) self.to_f.approx?(*args) end |
#ceil_multiple(multiple) ⇒ Object
Returns the multiple ceil of a number.
3 4 5 6 7 |
# File 'lib/nano/numeric/ceil_multiple.rb', line 3 def ceil_multiple(multiple) # gmosx: to_f is needed! # gmosx: IS THERE a more optimized way to do this? return ((self.to_f/multiple).ceil*multiple) end |
#distance(other) ⇒ Object
Returns the distance between self an another value. This is the same as #- but it provides an alternative for common naming between variant classes.
4.distance(3) #=> 1
9 10 11 |
# File 'lib/nano/numeric/distance.rb', line 9 def distance( other ) self - other end |
#pred(n = nil) ⇒ Object
Provides #pred as the opposite of #succ.
3.pred(2) #=> 1
9 10 11 12 |
# File 'lib/nano/numeric/pred.rb', line 9 def pred(n=nil) n ||= 1 self - n end |
#round_at(*args) ⇒ Object
To properly support Float’s rounding methods, Numeric must also be augmented.
19 20 21 |
# File 'lib/nano/float/round_at.rb', line 19 def round_at(*args) self.to_f.round_at(*args) end |
#round_to(*args) ⇒ Object
To properly support Float’s rounding methods, Numeric must also be augmented.
20 21 22 |
# File 'lib/nano/float/round_to.rb', line 20 def round_to(*args) self.to_f.round_to(*args) end |
#succ(n = nil) ⇒ Object
Allows #succ to take n increments.
3.succ(2) #=> 5
9 10 11 12 |
# File 'lib/nano/numeric/succ.rb', line 9 def succ(n=nil) n ||= 1 self + n end |
#to_b ⇒ Object
Provides a boolean interpretation of self. If self == 0 then false else true.
0.to_b #=> false
1.to_b #=> true
2.3.to_b #=> true
9 10 11 |
# File 'lib/nano/numeric/to_b.rb', line 9 def to_b self == 0 ? false : true end |