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 xml-simple by using the meta data in the hash to type cast values.
Example: "http://search.yahooapis.com/NewsSearchService/V1/newsSearch".to_uri.get( :appid => 'YahooDemo', :output => 'xml', :query => 'India', :results=> '3', :start => '1' ).deserialise.mutate_using(XmlSimpleTypeCaster.new)
36 37 38 39 40 |
# File 'lib/wrest/core_ext/hash/conversions.rb', line 36 def mutate_using(mutator) returning({})do |mutated_hash| self.each{|tuple| mutated_hash.store(*mutator.mutate(tuple))} end end |