PHP 8.2.31
Preview: rational.rb Size: 414 B
//proc/thread-self/root/opt/alt/ruby19/lib64/ruby/1.9.1/json/add/rational.rb

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

Directory Contents

Dirs: 0 × Files: 3

Name Size Perms Modified Actions
398 B lrw-r--r-- 2011-09-01 08:16:29
Edit Download
6.41 KB lrw-r--r-- 2013-02-13 07:18:58
Edit Download
414 B lrw-r--r-- 2011-09-01 08:16:29
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).