What is the difference between has_key? and include? in Ruby hash

I have been using has_key?(value) to check if the hash has any particular key.
But I came across the include?(value) in the below stackexchange post

How do I extract a sub-hash from a hash?

Can somebody explain whether both has_key and include are aliases for same ruby’s in built methods as mentioned in the below blog page?


Btw, both seem to work in ruby 2.1.6.

1 Like

If you read the second link you’ve provided it’s stated there. Hash#include? and Hash#has_key? are the same. One aliases the other. The feature he was proposing in that article will be the new comparable operators on Hash available in Ruby 2.3. eg) >= and <=