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) ⇒ 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.
-
#to_s ⇒ Object
A set node is rendered as its key.
Methods inherited from Node
#[], #ancestors, #detach, #dot, #key?, #parents, #root
Constructor Details
#initialize(parent, key) ⇒ Set
Returns a new instance of Set.
115 116 117 |
# File 'lib/hash_tree.rb', line 115 def initialize(parent, key) super(parent, @key = key) end |
Instance Attribute Details
#key ⇒ Object (readonly)
Key of this node
113 114 115 |
# File 'lib/hash_tree.rb', line 113 def key @key end |
Instance Method Details
#attach(child) ⇒ Object
119 |
# File 'lib/hash_tree.rb', line 119 def attach(child) do_attach(child.key, child) end |
#node_attach ⇒ Object
110 |
# File 'lib/hash_tree.rb', line 110 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 (‘.’)
129 |
# File 'lib/hash_tree.rb', line 129 def path() @path ||= ancestors(true)[1..-1].join(".") end |
#to_s ⇒ Object
A set node is rendered as its key
132 |
# File 'lib/hash_tree.rb', line 132 def to_s() key.to_s end |