I wish Ruby had a Hash#& method. I just need to quickly figure out the intersection of these two Hashes so I can push common data down into a common class.

Follow

@postmodern that does seem like something that would be in there. I would've tried about three different things before looking it up and finding out it didn't exist. 😂

Thing's I would've tried before googling:
hash1 & hash2
hash1.intersection(hash2)
hash1 - (hash1 - hash2)

But I guess if we want Hashes to work like Arrays...
(hash1.to_a & hash2.to_a).to_h

That seems like the most/least Ruby thing I've seen in awhile.

Sign in to participate in the conversation
Ruby.social

A Mastodon instance for Rubyists & friends