In Files

  • json/lib/json/add/rails.rb

Parent

Object

Public Class Methods

json_create(object) click to toggle source
 
               # File json/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
            

Public Instance Methods

to_json(*a) click to toggle source
 
               # File json/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