Class: Node
Defined Under Namespace
Classes: Attribute
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize ⇒ Node
constructor
A new instance of Node.
- #to_hash ⇒ Object
- #to_mash ⇒ Object
Methods inherited from Hash
Constructor Details
#initialize ⇒ Node
Returns a new instance of Node.
11 12 13 14 |
# File 'lib/node.rb', line 11 def initialize @data = {} super end |
Instance Method Details
#[](key) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/node.rb', line 23 def [](key) key = convert_key(key) case @data[key] when nil @data[key] = Node.new when Node::Attribute @data[key].value when Node @data[key] else raise "should never happen" end end |
#[]=(key, value) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/node.rb', line 16 def []=(key,value) key = convert_key(key) result = super attribute = Attribute.new(result) @data[key] = attribute end |
#to_hash ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/node.rb', line 37 def to_hash hash = {} @data.each do |key,item| if item.is_a?(Node) hash[key] = item.to_hash else hash[key] = item.value end end hash end |