OSDN Git Service

ActiveLdap 1.2.4
[redminele/redminele.git] / ruby / lib / ruby / gems / 1.8 / gems / activesupport-2.3.12 / lib / active_support / json / encoders / enumerable.rb
diff --git a/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/json/encoders/enumerable.rb b/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/json/encoders/enumerable.rb
new file mode 100644 (file)
index 0000000..65924e3
--- /dev/null
@@ -0,0 +1,17 @@
+module Enumerable
+  # Coerces the enumerable to an array for JSON encoding.
+  def as_json(options = nil) #:nodoc:
+    to_a
+  end
+end
+
+class Array
+  # Returns a JSON string representing the Array. +options+ are passed to each element.
+  def to_json(options = nil) #:nodoc:
+    "[#{map { |value| ActiveSupport::JSON.encode(value, options) } * ','}]"
+  end
+
+  def as_json(options = nil) #:nodoc:
+    self
+  end
+end