Flowdock
method

as_json

Importance_0
v3.0.5 - Show latest stable - 0 notes - Class: Hash
as_json(options = nil) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activesupport/lib/active_support/json/encoding.rb, line 219
  def as_json(options = nil) #:nodoc:
    # create a subset of the hash by applying :only or :except
    subset = if options
      if attrs = options[:only]
        slice(*Array.wrap(attrs))
      elsif attrs = options[:except]
        except(*Array.wrap(attrs))
      else
        self
      end
    else
      self
    end

    # use encoder as a proxy to call as_json on all values in the subset, to protect from circular references
    encoder = options && options[:encoder] || ActiveSupport::JSON::Encoding::Encoder.new(options)
    pairs = subset.map { |k, v| [k.to_s, encoder.as_json(v)] }
    result = self.is_a?(ActiveSupport::OrderedHash) ? ActiveSupport::OrderedHash.new : Hash.new
    pairs.inject(result) { |hash, pair| hash[pair.first] = pair.last; hash }
  end
Register or log in to add new notes.