Created
October 29, 2009 10:59
-
-
Save mudge/221351 to your computer and use it in GitHub Desktop.
A Rails initializer to use YAJL instead of ActiveSupport for JSON encoding.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use YAJL instead of ActiveSupport::JSON to encode objects to JSON in Rails. | |
class Hash | |
def to_json(options = nil) | |
Yajl::Encoder.encode(as_json(options)) | |
end | |
end | |
class Array | |
def to_json(options = nil) | |
Yajl::Encoder.encode(as_json(options)) | |
end | |
def as_json(options = nil) | |
map { |value| value.as_json(options) } | |
end | |
end | |
class Object | |
def to_json(options = nil) | |
Yajl::Encoder.encode(as_json(options)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment