"Did you mean?" Experience in Ruby

Everytime I misspelled a method name and got an error but didn't realize the typo, I kept saying,

"Weird, nothing looks weird..."

Sometimes I wasted hours and hours just because there is only one character difference. I hate it.

This is why I created the did_you_mean gem. What is does is whenever you get a NoMethodError or NameError, it'll automatically look up the method name you intended to call and suggest it to you. Installing it is as easy as:

gem 'did_you_mean', group: [:development, :test]

So what happens when you misspell ActiveSupport's Hash#with_indifferent_access? Here is what it looks like:

hash.with_inddiferent_access
# => NoMethodError: undefined method `with_inddiferent_access' for {}:Hash
#
#     Did you mean? #with_indifferent_access
#

Now you can just copy and paste what was suggested to your code.

The did_you_mean gem automagically adds method name suggestions to the error message. What this means is that you'll get a "Did you mean?" experience almost everywhere. Here is a good example of what it looks like from my real development:

screenshot-1

You can find more examples on the project page on GitHub: yuki24/did_you_mean

Start using the did_you_mean gem and stop worrying about misspelling. Ruby will just read your mind.

Show Comments

Get the latest posts delivered right to your inbox.