Skip to content

Instantly share code, notes, and snippets.

@honkster
Created July 2, 2010 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save honkster/461938 to your computer and use it in GitHub Desktop.
Save honkster/461938 to your computer and use it in GitHub Desktop.
# 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