Use Data#to_h and Struct#to_h for JSON encoding
`Hash[Array#zip]` was used before Struct supported #to_h. Data#to_h and Struct#to_h are also faster according to benchmarks: https://github.com/rails/rails/pull/47273/files#r1097994236
This commit is contained in:
parent
261f32d98d
commit
a7d4d78479
@ -68,14 +68,14 @@ def as_json(options = nil) # :nodoc:
|
||||
if RUBY_VERSION >= "3.2"
|
||||
class Data # :nodoc:
|
||||
def as_json(options = nil)
|
||||
Hash[members.zip(deconstruct)].as_json(options)
|
||||
to_h.as_json(options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Struct # :nodoc:
|
||||
def as_json(options = nil)
|
||||
Hash[members.zip(values)].as_json(options)
|
||||
to_h.as_json(options)
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user