Sha256: 07d46b2d7c53da5f2d318d282a7ae5e5cb6321671e261c5130fc189efda19350

Contents?: true

Size: 749 Bytes

Versions: 67

Compression:

Stored size: 749 Bytes

Contents

#frozen_string_literal: false
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
  require 'json'
end
defined?(::Complex) or require 'complex'

class Complex

  # Deserializes JSON string by converting Real value <tt>r</tt>, imaginary
  # value <tt>i</tt>, to a Complex object.
  def self.json_create(object)
    Complex(object['r'], object['i'])
  end

  # Returns a hash, that will be turned into a JSON object and represent this
  # object.
  def as_json(*)
    {
      JSON.create_id => self.class.name,
      'r'            => real,
      'i'            => imag,
    }
  end

  # Stores class name (Complex) along with real value <tt>r</tt> and imaginary value <tt>i</tt> as JSON string
  def to_json(*)
    as_json.to_json
  end
end

Version data entries

67 entries across 63 versions & 17 rubygems

Version Path
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/json-2.2.0/lib/json/add/complex.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/json-2.2.0/lib/json/add/complex.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/json-2.2.0/lib/json/add/complex.rb
tdiary-5.1.0 vendor/bundle/gems/json-2.2.0/lib/json/add/complex.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/json-2.2.0/lib/json/add/complex.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/json-2.2.0/lib/json/add/complex.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/json-2.2.0/lib/json/add/complex.rb
cloudsmith-api-0.44.4 vendor/bundle/ruby/2.3.0/gems/json-2.2.0/lib/json/add/complex.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/json-2.2.0/lib/json/add/complex.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/json-2.2.0/lib/json/add/complex.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/json-2.2.0/lib/json/add/complex.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/json-2.2.0/lib/json/add/complex.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/json-2.1.0/lib/json/add/complex.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/json-2.2.0/lib/json/add/complex.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/json-2.2.0/lib/json/add/complex.rb
ric-0.13.0 vendor/bundle/ruby/2.5.0/gems/json_pure-2.2.0/lib/json/add/complex.rb
cocoapods-dependency-html-0.0.2 vendor/bundle/gems/json-2.2.0/lib/json/add/complex.rb
cocoapods-dependency-html-0.0.1 vendor/bundle/gems/json-2.2.0/lib/json/add/complex.rb
ric-0.12.2 vendor/bundle/ruby/2.5.0/gems/json_pure-2.2.0/lib/json/add/complex.rb
tdiary-5.0.13 vendor/bundle/gems/json-2.2.0/lib/json/add/complex.rb