Code Review
/
packages
/
precise
/
mcollective.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
867cd92f05941408c035e636e1944e72d632477f
[packages/precise/mcollective.git]
/
lib
/
mcollective
/
vendor
/
json
/
lib
/
json
/
add
/
rational.rb
1
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
2
require 'json'
3
end
4
defined?(::Rational) or require 'rational'
5
6
class Rational
7
def self.json_create(object)
8
Rational(object['n'], object['d'])
9
end
10
11
def as_json(*)
12
{
13
JSON.create_id => self.class.name,
14
'n' => numerator,
15
'd' => denominator,
16
}
17
end
18
19
def to_json(*)
20
as_json.to_json
21
end
22
end