(think)

An online novel about the Source, the Force, the real life and everything in between...

The Elements of Style in Ruby #9: Hash#has_key? And Hash#has_value? Are Deprecated

One can often find similar code in the wild:

1
some_hash.has_key?(some_key)

has_something? predicates are not idiomatic in Ruby and Hash#has_key? and Hash#has_value? are nothing, but remnants of the early days of Ruby. In fact, according to Matz, they are deprecated in favor of Hash#key? and Hash#value?.

The above snippet should look like:

1
some_hash.key?(some_key)

As usual – you can use RuboCop to identify and fix such shortfalls of your code.

Comments