Class: Numeric
- Defined in:
- lib/rmtools/core/b.rb,
lib/rmtools/core/numeric.rb
Instance Method Summary collapse
- #b ⇒ Object
-
#between(min, max) ⇒ Object
is self lies between two numerics.
-
#ceil_to(i) ⇒ Object
ceil-round to i-fold.
-
#floor_to(i) ⇒ Object
floor-round to i-fold.
- #hex ⇒ Object
-
#mult_of(subj) ⇒ Object
is self multiple of numeric.
-
#round_to(i) ⇒ Object
closest-round to i-fold.
Instance Method Details
#b ⇒ Object
12 |
# File 'lib/rmtools/core/b.rb', line 12 def b; !zero? && self end |
#between(min, max) ⇒ Object
is self lies between two numerics
22 23 24 |
# File 'lib/rmtools/core/numeric.rb', line 22 def between(min, max) min < self and self < max end |
#ceil_to(i) ⇒ Object
ceil-round to i-fold
5 6 7 |
# File 'lib/rmtools/core/numeric.rb', line 5 def ceil_to(i) self + i - self % i end |
#floor_to(i) ⇒ Object
floor-round to i-fold
10 11 12 |
# File 'lib/rmtools/core/numeric.rb', line 10 def floor_to(i) self - self % i end |
#hex ⇒ Object
31 32 33 |
# File 'lib/rmtools/core/numeric.rb', line 31 def hex sprintf "%x", self end |
#mult_of(subj) ⇒ Object
is self multiple of numeric
27 28 29 |
# File 'lib/rmtools/core/numeric.rb', line 27 def mult_of(subj) self % subj == 0 end |
#round_to(i) ⇒ Object
closest-round to i-fold
15 16 17 18 19 |
# File 'lib/rmtools/core/numeric.rb', line 15 def round_to(i) ceil = ceil_to i floor = floor_to i ceil - self < self - floor ? ceil : floor end |