Sha256: f13672bd493afca71136662acfc29495f9d7d4132edabf12f16d732e2383afe2

Contents?: true

Size: 706 Bytes

Versions: 1

Compression:

Stored size: 706 Bytes

Contents

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/core-2.5.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.
      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
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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