class ZapiObject
Public Class Methods
new(hash: _generate hash: hash)
click to toggle source
# File lib/zapi_object.rb, line 3 def initialize hash: _generate hash: hash end
Public Instance Methods
_generate(hash: return nil unless hash.is_a? Hash)
click to toggle source
# File lib/zapi_object.rb, line 7 def _generate hash: return nil unless hash.is_a? Hash hash.each do |k,v| self.instance_variable_set("@#{k}", v) ## create and initialize an instance variable for this key/value pair self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")}) ## create the getter that returns the instance variable self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)}) ## create the setter that sets the instance variable end return self end
to_h()
click to toggle source
# File lib/zapi_object.rb, line 17 def to_h hash = {} self.instance_variables.each do |var| sym = var.to_s.delete("@").to_sym hash[sym] = self.instance_variable_get(var) end hash end