Class: Hash
Instance Method Summary collapse
Instance Method Details
#make_indifferent! ⇒ Object
2 3 4 5 6 7 |
# File 'lib/core_ext/hash.rb', line 2 def make_indifferent! keys_values = self.dup indifferent = Hash.new { |h,k| h[k.to_s] if Symbol === k } replace(indifferent) merge!(keys_values) end |
#nest! ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/core_ext/hash.rb', line 9 def nest! new_params = Hash.new.make_indifferent! each_pair do |full_key, value| this_param = new_params split_keys = full_key.split(/\]\[|\]|\[/) split_keys.each_index do |index| break if split_keys.length == index + 1 this_param[split_keys[index]] ||= Hash.new.make_indifferent! this_param = this_param[split_keys[index]] end this_param[split_keys.last] = value end clear replace(new_params) end |