Class: Trestle::Options

Inherits:
Hash
  • Object
show all
Defined in:
lib/trestle/options.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(hash = {}) ⇒ Object



3
4
5
# File 'lib/trestle/options.rb', line 3

def self.new(hash={})
  self[hash]
end

Instance Method Details

#merge(other, &block) ⇒ Object



7
8
9
# File 'lib/trestle/options.rb', line 7

def merge(other, &block)
  dup.merge!(other, &block)
end

#merge!(other, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/trestle/options.rb', line 11

def merge!(other, &block)
  super(other || {}) do |key, v1, v2|
    if v1.is_a?(Hash) && v2.is_a?(Hash)
      v1.merge(v2, &block)
    elsif v1.is_a?(Array)
      v1 + Array(v2)
    else
      v2
    end
  end
end