123456789_123456789_123456789_123456789_123456789_

Class: Rational

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

Class Method Summary

Instance Method Summary

Class Method Details

.json_create(object)

[ GitHub ]

  
# File 'ext/json/lib/json/add/rational.rb', line 7

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

Instance Method Details

#as_json

[ GitHub ]

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

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

#to_json

[ GitHub ]

  
# File 'ext/json/lib/json/add/rational.rb', line 19

def to_json(*)
  as_json.to_json
end