Class: HashTree::Set
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Key of this node.
Attributes inherited from Node
Instance Method Summary collapse
- #attach(child) ⇒ Object
-
#initialize(parent, key, attach: true) ⇒ Set
constructor
A new instance of Set.
- #node_attach ⇒ Object
-
#path ⇒ Object
Unique dot-separated list of keys leading from the root object to self.
- #retach(node) ⇒ Object
-
#to_s ⇒ Object
A set node is rendered as its key.
Methods inherited from Node
#[], #aggregate, #ancestors, #detach, #dot, #dot?, #each, #key?, #keys, #parents, #postorder, #preorder, #root, #traverse, #values
Constructor Details
#initialize(parent, key, attach: true) ⇒ Set
Returns a new instance of Set.
206 207 208 |
# File 'lib/hash_tree.rb', line 206 def initialize(parent, key, attach: true) super(parent, @key = key, attach: attach) end |
Instance Attribute Details
#key ⇒ Object (readonly)
Key of this node. TODO: Make it possible/required to alias this method to provide an internal key
204 205 206 |
# File 'lib/hash_tree.rb', line 204 def key @key end |
Instance Method Details
#attach(child) ⇒ Object
210 |
# File 'lib/hash_tree.rb', line 210 def attach(child) do_attach(child.key, child) end |
#node_attach ⇒ Object
200 |
# File 'lib/hash_tree.rb', line 200 alias node_attach attach |
#path ⇒ Object
Unique dot-separated list of keys leading from the root object to self. Note that the root object is not included in the path so that
obj.parent.nil? || obj.root.dot(obj.path) == obj
is always true
Note that for this to work, keys may not contain a dots (‘.’)
225 |
# File 'lib/hash_tree.rb', line 225 def path() @path ||= ancestors(true)[1..-1].map(&:key).join(".") end |
#retach(node) ⇒ Object
212 213 214 215 |
# File 'lib/hash_tree.rb', line 212 def retach(node) node.parent.detach(node.key) attach(node) end |
#to_s ⇒ Object
A set node is rendered as its key
228 |
# File 'lib/hash_tree.rb', line 228 def to_s() key.to_s end |