Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/delphix/utils.rb

Instance Method Summary collapse

Instance Method Details

#normalize_keysHash

Returns a new hash with all keys downcased and converted to symbols.

Returns:



57
58
59
# File 'lib/delphix/utils.rb', line 57

def normalize_keys
  transform_keys { |key| key.downcase.to_sym rescue key }
end

#recursively_normalize_keysHash

Returns a new Hash, recursively downcasing and converting all keys to symbols.

Returns:



66
67
68
# File 'lib/delphix/utils.rb', line 66

def recursively_normalize_keys
  recursively_transform_keys { |key| key.downcase.to_sym rescue key }
end

#recursively_transform_keys(&block) ⇒ Hash

Returns a new hash, recursively converting all keys by the block operation.

Returns:



94
95
96
# File 'lib/delphix/utils.rb', line 94

def recursively_transform_keys(&block)
  _recursively_transform_keys_in_object(self, &block)
end

#transform_keysHash

Returns a new hash with all keys converted using the block operation.

Examples:

hash = { name: 'Tigie', age: '15' }
hash.transform_keys{ |key| key.to_s.upcase }
  # => { "AGE" => "15", "NAME" => "Tigie" }

Returns:



80
81
82
83
84
85
86
87
# File 'lib/delphix/utils.rb', line 80

def transform_keys
  enum_for(:transform_keys) unless block_given?
  result = self.class.new
  each_key do |key|
    result[yield(key)] = self[key]
  end
  result
end