Add JSON::Any wrapper around JSON::Any#inspect output#15979
Add JSON::Any wrapper around JSON::Any#inspect output#15979straight-shoota merged 1 commit intocrystal-lang:masterfrom
JSON::Any wrapper around JSON::Any#inspect output#15979Conversation
f15c9b9 to
2cf6531
Compare
|
Rebased since I was out of date. |
2cf6531 to
9c1a31d
Compare
|
Added some more spec coverage to ensure state is reset at the end. |
|
I'm realizing we should probably do the same for YAML::Any |
|
Okay so the real proper Object Oriented Approved way to do this is to modify Array#inspect and Hash#inspect to use double recursion. Essentially this would mean defining something like: class Object
def inspect_recursive(io : IO) : Nil
inspect(io)
end
endand having all recursive calls to class Array
def inspect(io : IO) : Nil
# ...
join io, ", ", &.inspect_recursive(io)
end
endThen classes like JSON::Any could specify separate behaviour on the two. This is a much deeper-reaching change though, so I'd like thoughts on whether this stack-flag hack is preferable to that. |
|
I had a thought that we could use class Any
def inspect(io : IO)
io << "JSON::Any("
to_s(io)
io << ')'
end
def to_s(io : IO)
@raw.to_s(io)
end
endbut unfortunately Array#to_s calls into |
9c1a31d to
11d52e1
Compare
|
rebased. |
|
I presume for the YAML case we want this to show up in error messages as well? expect_raises(KeyError, %(Missing hash key: YAML::Any(nil))) do
any[YAML::Any.new(nil)]
end |
|
Hm, not sure about the error in |
JSON::Any wrapper around JSON::Any#inspect output
JSON::Any wrapper around JSON::Any#inspect outputJSON::Any, YAML::Any wrapper around Any#inspect output
JSON::Any, YAML::Any wrapper around Any#inspect outputJSON::Any wrapper around JSON::Any#inspect output
|
We're still missing the same for It should be fine to have only this in 1.18 and follow up with |
👍 |
Fixes #6213
See also #15953
This approach is admittedly a bit of a hack, and would benefit from Fiber-local variables other than what can be stored in
exec_recursive_hash.