Module Wrest::CoreExt::Hash::Conversions

  1. lib/wrest/core_ext/hash/conversions.rb

Makes it easier to build other objects from a Hash

Methods

public instance

  1. mutate_using

Public instance methods

mutate_using (mutator)

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(XmlSimpleTypeCaster.new)
[show source]
    # File lib/wrest/core_ext/hash/conversions.rb, line 36
36:         def mutate_using(mutator)
37:           mutated_hash = {}
38:             self.each{|tuple| mutated_hash.store(*mutator.mutate(tuple))}
39:           mutated_hash
40:         end