Module: DeepNest::Helpers

Included in:
Array, Hash
Defined in:
lib/deep_nest/helpers.rb

Instance Method Summary collapse

Instance Method Details

#deep_dupHash, Array

Returns a deep copy of the passed hash or array.

Parameters:

  • self (Hash, Array)

    The hash or array to be deep copied.

Returns:

  • (Hash, Array)

    The deep copy of the passed hash or array.



19
20
21
# File 'lib/deep_nest/helpers.rb', line 19

def deep_dup
  DeepNest.deep_dup(self)
end

#deep_equal?(other_structure) ⇒ true, false

Returns true if the passed parameters are same in structure and values, false otherwise.

Parameters:

  • self (Hash, Array)

    First structure to be compared.

  • other_structure (Hash, Array)

    Second structure to be compared.

Returns:

  • (true)

    If parameters are equal in structure and values.

  • (false)

    If parameters are not equal in structure and values.



47
48
49
# File 'lib/deep_nest/helpers.rb', line 47

def deep_equal?(other_structure)
  DeepNest.deep_equal?(self, other_structure)
end

#deep_merge(other_hash) {|&block| ... } ⇒ Hash

Returns a hash with the passed hashes recursively merged. An optional block can be passed to merge values.

Parameters:

  • self (Hash)

    The first hash to be merged.

  • other_hash (Hash)

    The second hash to be merged.

Yields:

  • (&block)

    Operation to merge values of the hashes.

Returns:

  • (Hash)

    The hash with recursively merged hashes.



33
34
35
# File 'lib/deep_nest/helpers.rb', line 33

def deep_merge(other_hash, &block)
  DeepNest.deep_merge(self, other_hash, &block)
end

#deep_stringify_keysHash, Array

Returns a hash or array with all hash keys converted to strings.

Parameters:

  • self (Hash, Array)

    The hash or array to stringify the keys

Returns:

  • (Hash, Array)

    The hash or array with stringified keys.



81
82
83
# File 'lib/deep_nest/helpers.rb', line 81

def deep_stringify_keys
  DeepNest.deep_stringify_keys(self)
end

#deep_symbolize_keysHash, Array

Returns a hash or array with all hash keys converted to symbols.

Parameters:

  • self (Hash, Array)

    The hash or array to symbolize the keys

Returns:

  • (Hash, Array)

    The hash or array with symbolized keys.



91
92
93
# File 'lib/deep_nest/helpers.rb', line 91

def deep_symbolize_keys
  DeepNest.deep_symbolize_keys(self)
end

#deep_transform_keys {|&block| ... } ⇒ Hash, Array

Returns a hash or array with all hash keys modified by the passed block.

Parameters:

  • self (Hash, Array)

    The hash or array to transform the keys.

Yields:

  • (&block)

    Operation to modify the keys.

Returns:

  • (Hash, Array)

    The hash or array with transformed keys.



59
60
61
# File 'lib/deep_nest/helpers.rb', line 59

def deep_transform_keys(&block)
  DeepNest.deep_transform_keys(self, &block)
end

#deep_transform_values {|&block| ... } ⇒ Hash, Array

Returns a hash or array with all hash values modified by the passed block.

Parameters:

  • self (Hash, Array)

    The hash or array to transform the values.

Yields:

  • (&block)

    Operation to modify the values.

Returns:

  • (Hash, Array)

    The hash or array with transformed values.



71
72
73
# File 'lib/deep_nest/helpers.rb', line 71

def deep_transform_values(&block)
  DeepNest.deep_transform_values(self, &block)
end