2007-12-21 08:48:59 +01:00
|
|
|
module Enumerable
|
2009-08-04 17:16:03 +02:00
|
|
|
# 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
|
2007-12-21 08:48:59 +01:00
|
|
|
end
|
|
|
|
end
|