Module: Committee::Utils

Defined in:
lib/committee/utils.rb

Class Method Summary collapse

Class Method Details

.deep_copy(from) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/committee/utils.rb', line 12

def self.deep_copy(from)
    if from.is_a?(Hash)
        h = Committee::Utils.indifferent_hash
        from.each_pair do |k, v|
        h[k] = deep_copy(v)
        end
        return h
    end

    if from.is_a?(Array)
        return from.map{ |v| deep_copy(v) }
    end

    return from
end

.indifferent_hashObject

Creates a Hash with indifferent access.

(Copied from Sinatra)



8
9
10
# File 'lib/committee/utils.rb', line 8

def self.indifferent_hash
    Hash.new { |hash,key| hash[key.to_s] if Symbol === key }
end