I must admit, this is pretty cool. Maybe not the most amazing thing you’ve ever heard of, but still, moves like this perfectly demonstrate the high functioning hive-mind of the ruby community. This new way to compare hashes was pretty sweet to me, so I wanted to share it with you.
#the old way of comparing hashes, which doesn't make sense.
{ a: 1, b: 2 }.include?({a: 1})
=> false
That evaluates to false because Hash#include can’t check for a key value pair, it can only check if the key exists.
#new to ruby 2.3
{ a: 1, b: 2 } >= { a: 1 }
=> true
{ a: 1, b: 2 } >= { a: 2 }
=> false
The hash on the top left is larger and includes the smaller hash on the right, so it evaluates to true. The one beneath is larger but doesn’t contain the key value pair on it’s right.
Have at it!
