Sha256: 9a5499f8bca008ca3f909abf7a3e3b295757ee1b993bb497d8d9d3b38176cb54

Contents?: true

Size: 414 Bytes

Versions: 435

Compression:

Stored size: 414 Bytes

Contents

unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
  require 'json'
end
defined?(::Rational) or require 'rational'

class Rational
  def self.json_create(object)
    Rational(object['n'], object['d'])
  end

  def as_json(*)
    {
      JSON.create_id => self.class.name,
      'n'            => numerator,
      'd'            => denominator,
    }
  end

  def to_json(*)
    as_json.to_json
  end
end

Version data entries

435 entries across 365 versions & 45 rubygems

Version Path
json-1.7.3-java lib/json/add/rational.rb
json_pure-1.7.3 lib/json/add/rational.rb
json-1.7.3 lib/json/add/rational.rb
json-1.7.2-java lib/json/add/rational.rb
json_pure-1.7.2 lib/json/add/rational.rb
json-1.7.2 lib/json/add/rational.rb
json-1.7.1-java lib/json/add/rational.rb
json_pure-1.7.1 lib/json/add/rational.rb
json-1.7.1 lib/json/add/rational.rb
json-1.7.0-java lib/json/add/rational.rb
json_pure-1.7.0 lib/json/add/rational.rb
json-1.7.0 lib/json/add/rational.rb
json-1.6.7-java lib/json/add/rational.rb
json_pure-1.6.7 lib/json/add/rational.rb
json-1.6.7 lib/json/add/rational.rb
horseman-0.0.5 vendor/ruby/1.9.1/gems/json-1.6.6/lib/json/add/rational.rb
horseman-0.0.5 vendor/ruby/1.9.1/gems/json_pure-1.6.6/lib/json/add/rational.rb
challah-0.5.4 vendor/bundle/gems/json-1.6.5/lib/json/add/rational.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/json-1.6.6/lib/json/add/rational.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/json-1.6.6/lib/json/add/rational.rb