Sha256: 3dfc88cb6aabd8d2e36ab7b99d422fa753bb87edbfab169c1487008925c46086

Contents?: true

Size: 1014 Bytes

Versions: 31

Compression:

Stored size: 1014 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 do
    # 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
  end
end

module Process
  class Status
    def as_json(options = nil)
      { :exitstatus => exitstatus, :pid => pid }
    end
  end
end

Version data entries

31 entries across 31 versions & 3 rubygems

Version Path
activesupport-4.0.13 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.13.rc1 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.11.1 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.12 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.11 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.10 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.10.rc2 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.10.rc1 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.9 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.8 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.7 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.6 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.6.rc3 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.6.rc2 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.6.rc1 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.5 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.4 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.4.rc1 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.3 lib/active_support/core_ext/object/to_json.rb
activesupport-4.0.2 lib/active_support/core_ext/object/to_json.rb