Method: HTTParty::CoreExt::HashConversions#to_struct

Defined in:
lib/httparty/core_ext/hash.rb

#to_structObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/httparty/core_ext/hash.rb', line 4

def to_struct
  o = OpenStruct.new
  self.each do |k, v|
    # if id, we create an accessor so we don't get warning about id deprecation
    if k.to_s == 'id'
      o.class.class_eval "attr_accessor :id"
      o.id = v
    else
      o.send("#{k}=", v.is_a?(Hash) ? v.to_struct : v)
    end
  end
  o
end