Sha256: 99d9a49a77354f321a9c97477c38c3a0fba3efb9fc644013f3dd12ff45cd908a

Contents?: true

Size: 793 Bytes

Versions: 5

Compression:

Stored size: 793 Bytes

Contents

module RDF
  ##
  # @since 0.2.0
  module Countable
    extend RDF::Util::Aliasing::LateBound

    ##
    # Returns `true` if `self` contains no RDF statements.
    #
    # @return [Boolean]
    def empty?
      each {return false}
      true
    end

    ##
    # Returns the number of RDF statements in `self`.
    #
    # @return [Integer]
    def count
      count = 0
      each { count += 1 }
      count
    end
    alias_method :size, :count

    ##
    # @private
    # @param  [Symbol, #to_sym] method
    # @return [Enumerator]
    # @see    Object#enum_for
    def enum_for(method = :each, *args)
      # Ensure that enumerators support the `#empty?` and `#count` methods:
      super.extend(RDF::Countable)
    end
    alias_method :to_enum, :enum_for
  end # Countable
end # RDF

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rdf-1.0.8 lib/rdf/mixin/countable.rb
rdf-1.1.0.p3 lib/rdf/mixin/countable.rb
rdf-1.0.7 lib/rdf/mixin/countable.rb
rdf-1.1.0.p2 lib/rdf/mixin/countable.rb
rdf-1.0.6 lib/rdf/mixin/countable.rb