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



324
325
326
327
328
329
330
# File 'lib/manywho.rb', line 324

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



315
316
317
318
319
320
321
# File 'lib/manywho.rb', line 315

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