Class: RBing::ResponseData
- Inherits:
-
Hash
- Object
- Hash
- RBing::ResponseData
- Defined in:
- lib/rbing.rb
Overview
Convenience wrapper for the response Hash. Converts keys to Strings. Crawls through all member data and converts any other Hashes it finds. Provides access to values through method calls, which will convert underscored to camel case.
Usage:
rd = ResponseData.new("AlphaBeta" => 1, "Results" => {"Gamma" => 2, "delta" => [3, 4]})
puts rd.alpha_beta
=> 1
puts rd.alpha_beta.results.gamma
=> 2
puts rd.alpha_beta.results.delta
=> [3, 4]
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object (private)
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rbing.rb', line 66 def method_missing(*args) name = args[0].to_s return self[name] if has_key? name camelname = name.split('_').map {|w| "#{w[0,1].upcase}#{w[1..-1]}" }.join("") if has_key? camelname self[camelname] else super *args end end |