Class: DEBUGGER__::AbbrevCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/debug/abbrev_command.rb

Defined Under Namespace

Classes: TrieNode

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ AbbrevCommand

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



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

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

Instance Method Details

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

Yields:

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


64
65
66
67
68
69
70
71
72
73
74
75
# 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