Updated mcollective.init according to OSCI-658
[packages/precise/mcollective.git] / lib / mcollective / vendor / json / lib / json / add / complex.rb
diff --git a/lib/mcollective/vendor/json/lib/json/add/complex.rb b/lib/mcollective/vendor/json/lib/json/add/complex.rb
new file mode 100644 (file)
index 0000000..d7ebebf
--- /dev/null
@@ -0,0 +1,22 @@
+unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
+  require 'json'
+end
+defined?(::Complex) or require 'complex'
+
+class Complex
+  def self.json_create(object)
+    Complex(object['r'], object['i'])
+  end
+
+  def as_json(*)
+    {
+      JSON.create_id => self.class.name,
+      'r'            => real,
+      'i'            => imag,
+    }
+  end
+
+  def to_json(*)
+    as_json.to_json
+  end
+end