Module: RubyAnagrams::Enumerable
Overview
Provides enumerable behavior to the trie data structure.
Instance Method Summary collapse
-
#each(&block) ⇒ Enumerator
Calls a block for each word in the trie data strucutre.
Instance Method Details
#each(&block) ⇒ Enumerator
Calls a block for each word in the trie data strucutre. If no block is given, an Enumerator is returned.
11 12 13 14 15 16 17 |
# File 'lib/anagrams/enumerable.rb', line 11 def each &block enumerator = Enumerator.new do |yielder| yielder << word if terminal? @children.each_value { |child| child.each { |word| yielder << word } } end block.nil? ? enumerator : enumerator.each(&block) end |