Class: Manywho::MyStruct

Inherits:
Object
  • Object
show all
Defined in:
lib/manywho.rb

Overview

Initialized with a JSON hash, each value of the hash is converted into an instance variable. Can also be easily converted into a JSON string

Instance Method Summary collapse

Constructor Details

#initialize(jsonValue) ⇒ MyStruct

Set instance values from the hash



328
329
330
331
332
333
334
# File 'lib/manywho.rb', line 328

def initialize(jsonValue)
    if (jsonValue != nil)
        jsonValue.each do
            |k,v| self.instance_variable_set("@#{k}", v)
        end
    end
end

Instance Method Details

#to_json(options = {}) ⇒ Object



319
320
321
322
323
324
325
# File 'lib/manywho.rb', line 319

def to_json(options= {})
    hash = {}
    self.instance_variables.each do |var|
        hash[var[1...var.length]] = self.instance_variable_get var
    end
    return hash.to_json
end