Class: Biosphere::Node::Attribute

Inherits:
Hash
  • Object
show all
Defined in:
lib/biosphere/node.rb

Instance Method Summary collapse

Instance Method Details

#deep_set(*args) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/biosphere/node.rb', line 9

def deep_set(*args)
    #puts "deep_set: #{args}"
    raise ArgumentError, "must pass at least one key, and a value" if args.length < 2
    value = args.pop
    args = args.first if args.length == 1 && args.first.kind_of?(Array)

    key = args.first
    raise ArgumentError, "must be a number" if self.kind_of?(Array) && !key.kind_of?(Numeric)

    if args.length == 1
        self[key] = value
    else
        child = self[key]
        unless child.respond_to?(:store_path)
            self[key] = self.class.new
            child = self[key]
        end
        child.deep_set(args[1..-1].push, value)
    end
end