123456789_123456789_123456789_123456789_123456789_

Class: DEBUGGER__::AbbrevCommand

Relationships & Source Files
Namespace Children
Classes:
Inherits: Object
Defined in: lib/debug/abbrev_command.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(config) ⇒ AbbrevCommand

config: { type: [commands…], … }

[ GitHub ]

  
# File 'lib/debug/abbrev_command.rb', line 48

def initialize config
  @trie = TrieNode.new
  build config
end

Instance Method Details

#build(config) (private)

[ GitHub ]

  
# File 'lib/debug/abbrev_command.rb', line 53

private def build config
  config.each do |type, commands|
    commands.each do |command|
      trie = @trie
      command.each_char do |c|
        trie = trie.append(c, type)
      end
    end
  end
end

#search(str, if_none = nil) {|trie.candidates.map{|s| str + s}| ... }

Yields:

  • (trie.candidates.map{|s| str + s})
[ GitHub ]

  
# File 'lib/debug/abbrev_command.rb', line 64

def search str, if_none = nil
  trie = @trie
  str.each_char do |c|
    if trie = trie[c]
      return trie.type if trie.type
    else
      return if_none
    end
  end
  yield trie.candidates.map{|s| str + s} if block_given?
  if_none
end