Updated mcollective.init according to OSCI-658
[packages/precise/mcollective.git] / lib / mcollective / vendor / json / lib / json / add / rational.rb
diff --git a/lib/mcollective/vendor/json/lib/json/add/rational.rb b/lib/mcollective/vendor/json/lib/json/add/rational.rb
new file mode 100644 (file)
index 0000000..867cd92
--- /dev/null
@@ -0,0 +1,22 @@
+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