After digging through the docs, this is as close as I've gotten, but it only grabs the first id. Do you know if there's a way to match and assign all ids?
With how pattern matching works, no, unfortunately. There can't be guarantees the next objects in that Array are all of the same structure or even type, so each subsequent node has either deconstruct or deconstruct_keys called on it.
I've been musing about my own DSL for searching through deeply nested structures because that's always a pain, but haven't experimented too much on it yet.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I'm just digging into pattern matching today for no real reason. I was trying to see if there was a cleaner way to write this with pattern matching:
After digging through the docs, this is as close as I've gotten, but it only grabs the first id. Do you know if there's a way to match and assign all ids?
With how pattern matching works, no, unfortunately. There can't be guarantees the next objects in that
Array
are all of the same structure or even type, so each subsequent node has eitherdeconstruct
ordeconstruct_keys
called on it.Now that said you might enjoy
jq
and the Ruby wrapper around it: github.com/winebarrel/ruby-jqI've been musing about my own DSL for searching through deeply nested structures because that's always a pain, but haven't experimented too much on it yet.