Class: PaypkgResponse
- Inherits:
-
Object
- Object
- PaypkgResponse
- Defined in:
- lib/paypkg.rb
Overview
The PaypkgResponse class converts a standard hash to a nested class object… NOTE: The outside object MUST BE a hash For example:
e = PaypkgResponse.new({'x'=>7,'a'=>[{'f'=>1},{'g'=>2}]})
yields:
<PaypkgResponse:0x00000004dc0e20 @x=7, @a=[#<PaypkgResponse:0x00000004dc0ce0 @f=1>, #<PaypkgResponse:0x00000004dc0bf0 @g=2>]>
and can be accessed like the example below.
Instance Method Summary collapse
-
#initialize(hash) ⇒ PaypkgResponse
constructor
A new instance of PaypkgResponse.
Constructor Details
#initialize(hash) ⇒ PaypkgResponse
Returns a new instance of PaypkgResponse.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/paypkg.rb', line 22 def initialize(hash) hash.each do |name, value| case when value.class==Array obj = [] value.each { |item| obj << PaypkgResponse.new(item) } self.class.__send__(:attr_accessor, name) instance_variable_set("@#{name}", obj) when value.class==Hash self.class.__send__(:attr_accessor, name) instance_variable_set("@#{name}", PaypkgResponse.new(value)) else self.class.__send__(:attr_accessor, name) instance_variable_set("@#{name}", value) end end end |