Class: SearchTree::Node
- Inherits:
-
Object
- Object
- SearchTree::Node
- Defined in:
- lib/chess_openings/search_tree.rb
Instance Attribute Summary collapse
-
#nodes ⇒ Object
Returns the value of attribute nodes.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #include?(key) ⇒ Boolean
-
#initialize(value) ⇒ Node
constructor
A new instance of Node.
- #is_leaf? ⇒ Boolean
- #keys ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(value) ⇒ Node
Returns a new instance of Node.
128 129 130 131 |
# File 'lib/chess_openings/search_tree.rb', line 128 def initialize(value) @value = value @nodes = {} end |
Instance Attribute Details
#nodes ⇒ Object
Returns the value of attribute nodes.
126 127 128 |
# File 'lib/chess_openings/search_tree.rb', line 126 def nodes @nodes end |
#value ⇒ Object
Returns the value of attribute value.
126 127 128 |
# File 'lib/chess_openings/search_tree.rb', line 126 def value @value end |
Instance Method Details
#==(other) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/chess_openings/search_tree.rb', line 149 def ==(other) return false if self.size != other.size || @value != other.value @nodes.keys.each do |key| return false unless other.keys.include?(key) end @nodes.keys.each do |key| return false if @nodes[key] != other.nodes[key] end true end |
#include?(key) ⇒ Boolean
145 146 147 |
# File 'lib/chess_openings/search_tree.rb', line 145 def include?(key) @nodes.keys.include?(key) end |
#is_leaf? ⇒ Boolean
133 134 135 |
# File 'lib/chess_openings/search_tree.rb', line 133 def is_leaf? @nodes.empty? end |
#keys ⇒ Object
141 142 143 |
# File 'lib/chess_openings/search_tree.rb', line 141 def keys @nodes.keys end |
#size ⇒ Object
137 138 139 |
# File 'lib/chess_openings/search_tree.rb', line 137 def size @nodes.size end |