Created
July 2, 2010 21:33
-
-
Save honkster/461938 to your computer and use it in GitHub Desktop.
This file contains 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
# To defeat Rails' conspiracy to have you not use the JSON gem. | |
# See activesupport-2.3.8/lib/active_support/json/encoding.rb line 92 gRRRRRRRRRRRRRRRR!!! | |
# Call UseJsonGemInRails.save_json_gem_to_json in your RAILS_ROOT/config/preinitializer.rb file. | |
# Then set up an initializer and call UseJsonGemInRails.reload_json_gem_to_json in it. | |
class UseJsonGemInRails | |
class << self | |
def save_json_gem_to_json | |
require 'json' | |
classes.each do |klass| | |
klass.class_eval do | |
alias_method :to_json_from_gem, :to_json | |
end | |
end | |
end | |
def reload_json_gem_to_json | |
(classes + [ActiveSupport::JSON::Variable]).each do |klass| | |
klass.class_eval do | |
alias_method :to_json, :to_json_from_gem | |
end | |
end | |
end | |
def classes | |
[ | |
Object, | |
Hash, | |
Array, | |
String, | |
Numeric, | |
Float, | |
Integer, | |
Regexp, | |
] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment