Sha256: 4029236efa3bc13eb2ae0d7a5248cd66a11c0e082a7b643a1184c108118d7e04

Contents?: true

Size: 662 Bytes

Versions: 6

Compression:

Stored size: 662 Bytes

Contents

class Integer

  unless method_defined?(:odd?)  # 1.8.7+

    # Returns true if this integer is odd, false otherwise.
    #
    #   2.odd?            #=> false
    #   3.odd?            #=> true
    #
    #   -99.odd?          # -> true
    #   -98.odd?          # -> false
    #
    # CREDIT: Daniel Schierbeck

    def odd?
      #self % 2 == 1
      self & 1 == 1
    end

  end

  unless method_defined?(:even?)  # 1.8.7+

    # Returns true if this integer is even, false otherwise.
    #
    #   2.even?  #=> true
    #   3.even?  #=> false
    #
    # CREDIT: Daniel Schierbeck

    def even?
      #self % 2 == 0
      self & 1 == 0
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
facets-2.8.4 lib/core/facets/integer/odd.rb
facets-2.8.3 lib/core/facets/integer/odd.rb
facets-2.8.2 lib/core/facets/integer/odd.rb
facets-2.8.1 lib/core/facets/integer/odd.rb
facets-2.8.0 lib/core/facets/integer/odd.rb
facets-2.7.0 lib/core/facets/integer/odd.rb