Class: HashTree::Set

Inherits:
Node
  • Object
show all
Defined in:
lib/hash_tree.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #parent

Instance Method Summary collapse

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

#keyObject (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_attachObject



110
# File 'lib/hash_tree.rb', line 110

alias node_attach attach

#pathObject

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_sObject

A set node is rendered as its key



132
# File 'lib/hash_tree.rb', line 132

def to_s() key.to_s end