class Hash
Public Instance Methods
camelize_keys(first_letter = :upper)
click to toggle source
Returns a new hash with all keys converted to UpperCamelCase strings.If th is set to :lower
then camelize produces lowerCamelCase.
hash = { my_name: 'Rob', my_age: '28' } hash.camelize_keys # => {"MyName"=>"Rob", "MyAge"=>"28"} hash.camelize_keys(:lower) # => {"myName"=>"Rob", "myAge"=>"28"}
# File lib/neb/core_ext.rb, line 15 def camelize_keys(first_letter = :upper) transform_keys { |key| key.to_s.camelize(first_letter) rescue key } end
camelize_keys!(first_letter = :upper)
click to toggle source
Destructively converts all keys to strings. Same as camelize_keys
, but modifies self
.
# File lib/neb/core_ext.rb, line 21 def camelize_keys!(first_letter = :upper) transform_keys! { |key| key.to_s.camelize(first_letter) rescue key } end
deep_camelize_keys(first_letter = :upper)
click to toggle source
Returns a new hash with all keys converted to UpperCamelCase strings.If th is set to :lower
then camelize produces lowerCamelCase. This includes the keys from the root hash and from all nested hashes and arrays.
hash = { my_name: 'Rob', my_age: '28', my_friend: { his_name: "bob" } } hash.deep_camelize_keys # => {"MyName"=>"Rob", "MyAge"=>"28", "MyFriend"=>{"HisName"=>"bob"}}
# File lib/neb/core_ext.rb, line 34 def deep_camelize_keys(first_letter = :upper) deep_transform_keys { |key| key.to_s.camelize(first_letter) rescue key } end
deep_camelize_keys!(first_letter = :upper)
click to toggle source
Destructively converts all keys to strings. Same as camelize_keys
, but modifies self
. This includes the keys from the root hash and from all nested hashes and arrays.
# File lib/neb/core_ext.rb, line 42 def deep_camelize_keys!(first_letter = :upper) deep_transform_keys! { |key| key.to_s.camelize(first_letter) rescue key } end