Class: JSONAble

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

Direct Known Subclasses

USStreet::Lookup, USZipcode::Lookup

Instance Method Summary collapse

Instance Method Details

#from_json!(string) ⇒ Object



12
13
14
15
16
# File 'lib/smartystreets_ruby_sdk/json_able.rb', line 12

def from_json!(string)
  JSON.load(string).each do |var, val|
    self.instance_variable_set var, val
  end
end

#to_json(options = {}) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/smartystreets_ruby_sdk/json_able.rb', line 4

def to_json(options={})
  hash = {}
  self.instance_variables.each do |var|
    hash[var.to_s.delete('@')] = self.instance_variable_get var
  end
  hash.to_json
end