123456789_123456789_123456789_123456789_123456789_

Class: Complex

Relationships & Source Files
Inherits: Object
Defined in: ext/json/lib/json/add/complex.rb

Class Method Summary

  • .json_create(object)

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

Instance Method Summary

  • #as_json

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

  • #to_json(*args)

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

Class Method Details

.json_create(object)

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

[ GitHub ]

  
# File 'ext/json/lib/json/add/complex.rb', line 11

def self.json_create(object)
  Complex(object['r'], object['i'])
end

Instance Method Details

#as_json

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

[ GitHub ]

  
# File 'ext/json/lib/json/add/complex.rb', line 17

def as_json(*)
  {
    JSON.create_id => self.class.name,
    'r'            => real,
    'i'            => imag,
  }
end

#to_json(*args)

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

[ GitHub ]

  
# File 'ext/json/lib/json/add/complex.rb', line 26

def to_json(*args)
  as_json.to_json(*args)
end