The JSON gem adds a few modules to Ruby core classes containing :to_json definition, overwriting their default behavior. That said, we need to define the basic to_json method in all of them, otherwise they will always use to_json gem implementation, which is backwards incompatible in several cases (for instance, the JSON implementation for Hash does not work) with inheritance and consequently classes as ActiveSupport::OrderedHash cannot be serialized to json.
On the other hand, we should avoid conflict with ::JSON.{generate,dump}(obj). Unfortunately, the JSON gem's encoder relies on its own to_json implementation to encode objects. Since it always passes a ::JSON::State object as the only argument to to_json, we can detect that and forward the calls to the original to_json method.
It should be noted that when using ::JSON.{generate,dump} directly, ActiveSupport's encoder is bypassed completely. This means that as_json won't be invoked and the JSON gem will simply ignore any options it does not natively understand. This also means that ::JSON.{generate,dump} should give exactly the same results with or without active support.
- MODULE ActiveSupport::Autoload
- MODULE ActiveSupport::Benchmarkable
- MODULE ActiveSupport::Cache
- MODULE ActiveSupport::Callbacks
- MODULE ActiveSupport::Concern
- MODULE ActiveSupport::Concurrency
- MODULE ActiveSupport::Configurable
- MODULE ActiveSupport::Dependencies
- MODULE ActiveSupport::DescendantsTracker
- MODULE ActiveSupport::Gzip
- MODULE ActiveSupport::Inflector
- MODULE ActiveSupport::JSON
- MODULE ActiveSupport::LazyLoadHooks
- MODULE ActiveSupport::Multibyte
- MODULE ActiveSupport::Notifications
- MODULE ActiveSupport::NumberHelper
- MODULE ActiveSupport::NumericWithFormat
- MODULE ActiveSupport::PerThreadRegistry
- MODULE ActiveSupport::QualifiedConstUtils
- MODULE ActiveSupport::RangeWithFormat
- MODULE ActiveSupport::Rescuable
- MODULE ActiveSupport::SecurityUtils
- MODULE ActiveSupport::TaggedLogging
- MODULE ActiveSupport::Testing
- MODULE ActiveSupport::VERSION
- MODULE ActiveSupport::XmlMini
- MODULE ActiveSupport::XmlMini_LibXMLSAX
- MODULE ActiveSupport::XmlMini_Nokogiri
- MODULE ActiveSupport::XmlMini_NokogiriSAX
- CLASS ActiveSupport::ArrayInquirer
- CLASS ActiveSupport::BacktraceCleaner
- CLASS ActiveSupport::CachingKeyGenerator
- CLASS ActiveSupport::Deprecation
- CLASS ActiveSupport::DeprecationException
- CLASS ActiveSupport::Duration
- CLASS ActiveSupport::EventedFileUpdateChecker
- CLASS ActiveSupport::ExecutionWrapper
- CLASS ActiveSupport::Executor
- CLASS ActiveSupport::FileUpdateChecker
- CLASS ActiveSupport::HashWithIndifferentAccess
- CLASS ActiveSupport::InheritableOptions
- CLASS ActiveSupport::KeyGenerator
- CLASS ActiveSupport::LogSubscriber
- CLASS ActiveSupport::Logger
- CLASS ActiveSupport::MessageEncryptor
- CLASS ActiveSupport::MessageVerifier
- CLASS ActiveSupport::OrderedHash
- CLASS ActiveSupport::OrderedOptions
- CLASS ActiveSupport::ProxyObject
- CLASS ActiveSupport::Railtie
- CLASS ActiveSupport::Reloader
- CLASS ActiveSupport::SafeBuffer
- CLASS ActiveSupport::StringInquirer
- CLASS ActiveSupport::Subscriber
- CLASS ActiveSupport::TestCase
- CLASS ActiveSupport::TimeWithZone
- CLASS ActiveSupport::TimeZone
- CLASS ActiveSupport::XMLConverter
- G
- V
Returns the version of the currently loaded Active Support as a
Gem::Version
.
Returns the version of the currently loaded ActiveSupport as a Gem::Version