Module: Wrest::CoreExt::Hash::Conversions
- Included in:
- Hash
- Defined in:
- lib/wrest/core_ext/hash/conversions.rb
Overview
Makes it easier to build other objects from a Hash
Instance Method Summary collapse
-
#mutate_using(mutator) ⇒ Object
This method accepts a hash mutator (found in Wrest::Compononents) to build a new hash map by making changes to an existing one.
Instance Method Details
#mutate_using(mutator) ⇒ Object
This method accepts a hash mutator (found in Wrest::Compononents) to build a new hash map by making changes to an existing one.
No, this method does not mutate the state of the hash it is invoked on, but rather builds a new one.
Yes, the name is misleading in that respect. However, one hopes the absence of an exclamation mark will increase clarity.
Uses include mutating the hash produced by deserialising xml by using the meta data in the hash to type cast values.
Example: “search.yahooapis.com/NewsSearchService/V1/newsSearch”.to_uri.get(
:appid => 'YahooDemo',
:output => 'xml',
:query => 'India',
:results=> '3',
:start => '1'
).deserialise.mutate_using(XmlTypeCaster.new)
37 38 39 40 41 |
# File 'lib/wrest/core_ext/hash/conversions.rb', line 37 def mutate_using(mutator) mutated_hash = {} each { |tuple| mutated_hash.store(*mutator.mutate(tuple)) } mutated_hash end |