Sha256: d977c070810edb77dd6185117f5f5268df195b67393a12a61a37031c3cb868c3

Contents?: true

Size: 911 Bytes

Versions: 97

Compression:

Stored size: 911 Bytes

Contents

# Hack to load json gem first so we can overwrite its to_json.
begin
  require 'json'
rescue LoadError
end

# 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.
[Object, Array, FalseClass, Float, Hash, Integer, NilClass, String, TrueClass].each do |klass|
  klass.class_eval <<-RUBY, __FILE__, __LINE__
    # Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info.
    def to_json(options = nil)
      ActiveSupport::JSON.encode(self, options)
    end
  RUBY
end

Version data entries

97 entries across 97 versions & 4 rubygems

Version Path
dirty_history-0.4.10 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/object/to_json.rb
dirty_history-0.4.9 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/object/to_json.rb
dirty_history-0.4.8 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/object/to_json.rb
dirty_history-0.4.7 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/object/to_json.rb
dirty_history-0.4.6 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/object/to_json.rb
dirty_history-0.4.5 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/object/to_json.rb
dirty_history-0.4.4 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/object/to_json.rb
dirty_history-0.4.3 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/object/to_json.rb
dirty_history-0.4.2 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/object/to_json.rb
activesupport-3.1.3 lib/active_support/core_ext/object/to_json.rb
activesupport-3.1.2 lib/active_support/core_ext/object/to_json.rb
activesupport-3.0.11 lib/active_support/core_ext/object/to_json.rb
activesupport-3.1.2.rc2 lib/active_support/core_ext/object/to_json.rb
activesupport-3.1.2.rc1 lib/active_support/core_ext/object/to_json.rb
dirty_history-0.3.0 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/object/to_json.rb
activesupport-3.1.1 lib/active_support/core_ext/object/to_json.rb
activesupport-3.1.1.rc3 lib/active_support/core_ext/object/to_json.rb
activesupport-3.1.1.rc2 lib/active_support/core_ext/object/to_json.rb
messagebus_ruby_api-0.4.7 spec/ruby/1.9.1/gems/activesupport-3.0.9/lib/active_support/core_ext/object/to_json.rb
activesupport-3.1.1.rc1 lib/active_support/core_ext/object/to_json.rb