method
as_json
v8.1.1 -
Show latest stable
- Class:
Hash
as_json(options = nil)public
No documentation available.
# File activesupport/lib/active_support/core_ext/object/json.rb, line 175
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(attrs))
elsif attrs = options[:except]
except(*Array(attrs))
else
self
end
else
self
end
result = {}
if options
options = options.dup.freeze unless options.frozen?
subset.each { |k, v| result[k.to_s] = v.as_json(options) }
else
subset.each { |k, v| result[k.to_s] = v.as_json }
end
result
end