Class: Complex (Ruby 2.3.4)

Complex

Public Class Methods

json_create(object)

Deserializes JSON string by converting Real value r, imaginary value i, to a Complex object.

 
               # File json/lib/json/add/complex.rb, line 11
def self.json_create(object)
  Complex(object['r'], object['i'])
end
            

Public Instance Methods

as_json(*)

Returns a hash, that will be turned into a JSON object and represent this object.

 
               # File json/lib/json/add/complex.rb, line 17
def as_json(*)
  {
    JSON.create_id => self.class.name,
    'r'            => real,
    'i'            => imag,
  }
end
            
to_json(*)

Stores class name (Complex) along with real value r and imaginary value i as JSON string

 
               # File json/lib/json/add/complex.rb, line 26
def to_json(*)
  as_json.to_json
end