I wrote this helper class a few days ago:
class ObjectifiedHash def initialize hash @data = hash.inject({}) do |data, (key,value)| value = ObjectifiedHash.new value if value.kind_of? Hash data[key.to_s] = value data end end def method_missing key if @data.key? key.to_s @data[key.to_s] else nil end end end
Usage example:
ojson = ObjectifiedHash.new(HTTParty.get('http://api.dribbble.com/players/simplebits')) ojson.shots_counts
source share