Class | Integer
In: | lib/core/facets/integer/bitmask.rb lib/core/facets/integer/factorial.rb lib/core/facets/integer/multiple.rb lib/core/facets/integer/odd.rb lib/core/facets/integer/of.rb lib/core/facets/integer/ordinal.rb lib/core-uncommon/facets/integer/roman.rb lib/standard/facets/random.rb
Parent: | Object

### Methods

bit bit? bit_clear bitmask bitmask? even? fac factorial multiple? odd? of ordinal ordinalize roman times_collect times_map

### Included Modules

Random::IntegerExtensions

### Constants

ROMAN_MAX | = | 3999 unless const_defined?(:ROMAN_MAX) |  |
ROMAN_VALUES | = | [ ["M", 1000], ["CM", 900], ["D", 500], ["CD", 400], ["C", 100], ["XC", 90], ["L", 50], ["XL", 40], ["X", 10], ["IX", 9], ["V", 5], ["IV", 4], ["I", 1] |  |

### Public Instance methods

bit(bit)

Set a bit.

      0.bit(4)  #=> 16

Using a negative figure will clear a bit.

      10.bit(-4)      #=> 2

This is more easily seen using binary.

      0b0100.bit(-3)  #=> 0

CREDIT: Thomas Sawyer, George Moschovitis

bit?(bit)

Is a bit set?

      8.bit?(3)  #=> true
      8.bit?(2)  #=> false

CREDIT: Thomas Sawyer, George Moschovitis

bit_clear(bit)

Clear bit.

CREDIT: George Moschovitis

bitmask(mask)

Apply a bitmask.

      1.bitmask(6) #=> 7

Using a inverted bitmask clears bits.

      7.bitmask(~2) #=> 5
      5.bitmask(~2) #=> 5

CREDIT: George Moschovitis

bitmask?(mask)

Is bitmask set?

      7.bitmask?(7) #=> true
      7.bitmask?(5) #=> true
      8.bitmask?(3) #=> false

CREDIT: George Moschovitis

even?()

Returns true if this integer is even, false otherwise.

      2.even?  #=> true
      3.even?  #=> false

CREDIT: Daniel Schierbeck

fac()

Alias for factorial

factorial()

Calculate the factorial of an integer.

      2.factorial  #=> 2
      3.factorial  #=> 6
      4.factorial  #=> 24

CREDIT: Malte Milatz

multiple?(number)

Is `self` a multiple of a given number?

      7.multiple?(2)  #=> false
      8.multiple?(2)  #=> true

CREDIT: Trans

odd?()

Returns true if this integer is odd, false otherwise.

      2.odd?            #=> false
      3.odd?            #=> true

      -99.odd?          # -> true
      -98.odd?          # -> false

CREDIT: Daniel Schierbeck

of(&block)

Like times but returns a collection of the yield results.

      a = 3.of { |i| "#{i+1}" }
      a #=> [ "1", "2", "3" ]

ordinal()
ordinalize()

Alias for ordinal

roman()

Converts this integer to a roman numeral.

NOTE: This is not (presently) a common core extension and is not loaded automatically when using `require ‘facets‘`.

times_collect(&block)

Alias for of

times_map(&block)

Alias for of

[Validate]