Module: Xqsr3::HashUtilities::DeepTransform
- Included in:
- Hash
- Defined in:
- lib/xqsr3/doc_.rb,
lib/xqsr3/hash_utilities/deep_transform.rb
Overview
Exception-related utilities
Components of interest
-
::Xqsr3::Diagnostics::HashUtilities::deep_transform
-
::Xqsr3::Diagnostics::HashUtilities::deep_transform!
Class Method Summary collapse
Instance Method Summary collapse
-
#deep_transform(&block) ⇒ Object
Executes the given mandatory 1- or 2-parameter block on the receiving instance, which must be a Hash or a type that responds to the
mapmessage, returning a copy of the instance in which keys (1-parameter block) or keys and values (2-parameter block) are transformed. -
#deep_transform!(&block) ⇒ Object
Executes the given mandatory 1- or 2-parameter block on the receiving instance, whihc must be a Hash or a type that responds to
[],delete, andkeysmessages, changing the keys (1-parameter block) or keys and values (2-parameter block).
Class Method Details
.do_deep_transform_on_hashlike_(h, &block) ⇒ Object
:nodoc:
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/xqsr3/hash_utilities/deep_transform.rb', line 62 def self.do_deep_transform_on_hashlike_ h, &block # :nodoc: ::Xqsr3::Quality::ParameterChecking.check_parameter h, 'h', responds_to: [ :map ] case block.arity when 1 h = Hash[h.map do |k, v| k = k.deep_transform(&block) if ::Hash === k v = v.deep_transform(&block) if ::Hash === v [yield(k), v] end] when 2 h = Hash[h.map do |k, v| k = k.deep_transform(&block) if ::Hash === k v = v.deep_transform(&block) if ::Hash === v yield(k, v) end] else raise ArgumentError, "block arity must be 1 or 2" end h end |
Instance Method Details
#deep_transform(&block) ⇒ Object
Executes the given mandatory 1- or 2-parameter block on the receiving instance, which must be a Hash or a type that responds to the map message, returning a copy of the instance in which keys (1-parameter block) or keys and values (2-parameter block) are transformed.
133 134 135 136 |
# File 'lib/xqsr3/hash_utilities/deep_transform.rb', line 133 def deep_transform &block DeepTransform.do_deep_transform_on_hashlike_(self, &block) end |
#deep_transform!(&block) ⇒ Object
This method is not strongly exception-safe - failure during transformation can result in a partially transformed instance
Executes the given mandatory 1- or 2-parameter block on the receiving instance, whihc must be a Hash or a type that responds to [], delete, and keys messages, changing the keys (1-parameter block) or keys and values (2-parameter block).
145 146 147 148 |
# File 'lib/xqsr3/hash_utilities/deep_transform.rb', line 145 def deep_transform! &block do_deep_transform_on_self_(&block) end |