Sha256: 88156300775ba04b012f47d905e4d1ad573023d4e2b27cd65e05d1f9cf9f55b8

Contents?: true

Size: 574 Bytes

Versions: 2

Compression:

Stored size: 574 Bytes

Contents

module Rambling
  module Trie
    # Provides enumerable behavior to the Trie data structure.
    module Enumerable
      include ::Enumerable

      alias_method :size, :count

      # Calls block once for each of the words contained in the trie. If no block given, an Enumerator is returned.
      def each(&block)
        enumerator = Enumerator.new do |words|
          words << as_word if terminal?
          children.each { |child| child.each { |word| words << word } }
        end

        block.nil? ? enumerator : enumerator.each(&block)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rambling-trie-0.6.1 lib/rambling/trie/enumerable.rb
rambling-trie-0.6.0 lib/rambling/trie/enumerable.rb