Method: Hash#as_json
- Defined in:
- activesupport/lib/active_support/core_ext/object/json.rb
#as_json(options = nil) ⇒ Object
:nodoc:
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'activesupport/lib/active_support/core_ext/object/json.rb', line 175 def as_json( = nil) # :nodoc: # create a subset of the hash by applying :only or :except subset = if if attrs = [:only] slice(*Array(attrs)) elsif attrs = [:except] except(*Array(attrs)) else self end else self end result = {} if = .dup.freeze unless .frozen? subset.each { |k, v| result[k.to_s] = v.as_json() } else subset.each { |k, v| result[k.to_s] = v.as_json } end result end |