Sha256: b868d40daa4c505c6e1f7bb5f5f35021635206020bf7e9e290a29dd821a64b19

Contents?: true

Size: 689 Bytes

Versions: 1

Compression:

Stored size: 689 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.4.0/Enumerable.html#method-i-count
      # Enumerable}
      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.each 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-0.9.3 lib/rambling/trie/enumerable.rb