Class: Object

Inherits:
BasicObject
Defined in:
lib/json/add/rails.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.json_create(object) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/json/add/rails.rb', line 10

def self.json_create(object)
  obj = new
  for key, value in object
    next if key == JSON.create_id
    instance_variable_set "@#{key}", value
  end
  obj
end

Instance Method Details

#to_json(*a) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/json/add/rails.rb', line 19

def to_json(*a)
  result = {
    JSON.create_id => self.class.name
  }
  instance_variables.inject(result) do |r, name|
    r[name[1..-1]] = instance_variable_get name
    r
  end
  result.to_json(*a)
end