Created
March 17, 2022 03:46
-
-
Save ndkhoa/f96bb416b2bf09edaa630d383807676f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Select food_ids | |
| pets = { | |
| dogs: [ | |
| { | |
| dog_id: '5d10ffdb-94df-4265-960c-39fa8a86e258', | |
| foods: [ | |
| 'e2501f63-af85-410e-8f7a-da47ffd5ce0e', | |
| ], | |
| }, | |
| { | |
| dog_id: 'f80c5a13-34fa-43d2-8d64-80d0bf2e1161', | |
| foods: [ | |
| '821d66ee-03e7-41dd-a1a5-248458b2b5e0', | |
| '5836caa8-a738-4b28-83e4-eb0e69ea82b0', | |
| ], | |
| }, | |
| ], | |
| cats: [ | |
| { | |
| cat_id: '76752e2c-5033-4619-a2d9-445067ccbd09', | |
| foods: [ | |
| 'f2944c90-ce9a-4f8e-b5cd-9a8177e918ed', | |
| 'e2a343f8-8998-4d29-abbc-0aee27ab986f', | |
| ], | |
| }, | |
| ], | |
| } |
Author
ndkhoa
commented
Mar 17, 2022
require 'hashie'
# https://github.com/hashie/hashie#deepfind
pets.extend Hashie::Extensions::DeepFind
food_ids = pets.deep_find_all(:foods).flatten
puts food_ids
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment