Class: DEBUGGER__::AbbrevCommand::TrieNode

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

Instance Method Summary collapse

Constructor Details

#initializeTrieNode

Returns a new instance of TrieNode.



5
6
7
8
# File 'lib/debug/abbrev_command.rb', line 5

def initialize
  @children = {}
  @types = {} # set
end

Instance Method Details

#[](c) ⇒ Object



15
16
17
# File 'lib/debug/abbrev_command.rb', line 15

def [](c)
  @children[c]
end

#add_type(type) ⇒ Object



19
20
21
22
# File 'lib/debug/abbrev_command.rb', line 19

def add_type type
  @types[type] = true
  self
end

#append(c, type) ⇒ Object



10
11
12
13
# File 'lib/debug/abbrev_command.rb', line 10

def append c, type
  trie = (@children[c] ||= TrieNode.new)
  trie.add_type type
end

#candidatesObject



36
37
38
39
40
41
42
43
44
# File 'lib/debug/abbrev_command.rb', line 36

def candidates
  @children.map{|c, n|
    ss = n.candidates
    ss.empty? ? c :
    ss.map{|s|
      c+s
    }
  }.flatten
end

#typeObject



28
29
30
31
32
33
34
# File 'lib/debug/abbrev_command.rb', line 28

def type
  if @types.size == 1
    @types.keys.first
  else
    nil
  end
end

#typesObject



24
25
26
# File 'lib/debug/abbrev_command.rb', line 24

def types
  @types.keys
end