Sha256: 1db97b2d1a4c27d06414e6030a122bd1fa15001d89a7cc053073a627481965f9

Contents?: true

Size: 759 Bytes

Versions: 1

Compression:

Stored size: 759 Bytes

Contents

# frozen_string_literal: true

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

      # Returns number of words contained in the trie
      # @see https://ruby-doc.org/3.3.0/Enumerable.html#method-i-count Enumerable#count
      alias_method :size, :count

      # Iterates over the words contained in the trie.
      # @yield [String] the words contained in this trie node.
      # @return [self]
      def each
        return enum_for :each unless block_given?

        yield as_word if terminal?

        children_tree.each_value do |child|
          child.each do |word|
            yield word
          end
        end

        self
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rambling-trie-2.5.0 lib/rambling/trie/enumerable.rb