Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/typeform/core_ext/hash/keys.rb
Instance Method Summary collapse
-
#camelize_keys ⇒ Object
Returns a new hash with all keys converted to camelcase strings.
-
#deep_camelize_keys ⇒ Object
Returns a new hash with all keys converted to camelcase strings.
-
#deep_underscore_keys ⇒ Object
Returns a new hash with all keys converted to underscore strings.
-
#transform_keys ⇒ Object
Returns a new hash with all keys converted using the
block
operation. -
#underscore_keys ⇒ Object
Returns a new hash with all keys converted to underscore strings.
Instance Method Details
#camelize_keys ⇒ Object
Returns a new hash with all keys converted to camelcase strings.
hash = { first_name: "Rob", last_name: "Bob" }
hash.camelize_keys
# => {:firstName=>"Rob", :lastName=>"Bob"}
30 31 32 |
# File 'lib/typeform/core_ext/hash/keys.rb', line 30 def camelize_keys transform_keys { |key| camelize_key(key) } end |
#deep_camelize_keys ⇒ Object
Returns a new hash with all keys converted to camelcase strings. This includes the keys from the root hash and from all nested hashes and arrays.
hash = { person: { first_name: "Rob", last_name: "Bob" } }
hash.deep_camelize_keys
# => {:person=>{:firstName=>"Rob", :lastName=>"Bob"}}
54 55 56 |
# File 'lib/typeform/core_ext/hash/keys.rb', line 54 def deep_camelize_keys deep_transform_keys_in_object(self) { |key| camelize_key(key) } end |
#deep_underscore_keys ⇒ Object
Returns a new hash with all keys converted to underscore strings. This includes the keys from the root hash and from all nested hashes and arrays.
hash = { person: { firstName: "Rob", lastName: "Bob" } }
hash.deep_underscore_keys
# => {:person=>{:first_name=>"Rob", :last_name=>"Bob"}}
42 43 44 |
# File 'lib/typeform/core_ext/hash/keys.rb', line 42 def deep_underscore_keys deep_transform_keys_in_object(self) { |key| underscore_key(key) } end |
#transform_keys ⇒ Object
Returns a new hash with all keys converted using the block
operation.
5 6 7 8 9 10 11 12 |
# File 'lib/typeform/core_ext/hash/keys.rb', line 5 def transform_keys return enum_for(:transform_keys) { size } unless block_given? result = {} each_key do |key| result[yield(key)] = self[key] end result end |
#underscore_keys ⇒ Object
Returns a new hash with all keys converted to underscore strings.
hash = { firstName: "Rob", lastName: "Bob" }
hash.underscore_keys
# => {:first_name=>"Rob", :last_name=>"Bob"}
20 21 22 |
# File 'lib/typeform/core_ext/hash/keys.rb', line 20 def underscore_keys transform_keys { |key| underscore_key(key) } end |