Introducing Pry-Byetypo 👋
If you’re anything like me, it’s likely that you have sausage-like fingers.🌭
As a result, you might find yourself making typos on your REPL daily.
This is why I am thrilled to introduce Pry-Byetypo.
It is a small Pry plugin who captures exceptions that may arise from typos and deduces the correct command based on your database information and session history.
For a while, Ruby has come with the useful DidYouMean gem. It’s likely that you’ve already experienced it. It suggests potential commands for you to run.
irb(main):001> methodss
(irb):1:in `<main>': undefined local variable or method `methodss' for main:Object (NameError)
Did you mean? methods
method
from /Users/clementmo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/irb-1.11.1/exe/irb:9:in `<top (required)>'
from /Users/clementmo/.rbenv/versions/3.2.2/bin/irb:25:in `load'
from /Users/clementmo/.rbenv/versions/3.2.2/bin/irb:25:in `<main>'
irb(main):002>With Pry-Byetypo, we will autocorrect the command and run it in your REPL. For V1, we handle a few errors such as:
- NameError — undefined local variable or method
- NameError — uninitialized constant
- ActiveRecord::ConfigurationError
- ActiveRecord::StatementInvalid
I don’t want to spoil the README, so let’s just take a look at the NameError: uninitialized constant error with a basic example.
Get Clément Morisset’s stories in your inbox
Join Medium for free to get updates from this writer.
Without Pry-Byetypo
[2] pry(main)> Account::Usert.last
NameError: uninitialized constant Account::Usert
from (pry):2:in `__pry__'
[3] pry(main)>With Pry-Byetypo
[2] pry(main)> Account::Usert.last
I, [2024-01-13T20:00:16.280710 #694] ERROR -- : uninitialized constant Account::Usert
I, [2024-01-13T20:00:16.281237 #694] INFO -- : Running: Account::User
=> #<Account::User id: 1, email: "yo@email.com">What happens under the hood?
The first time you open a Pry instance with the gem installed, we will read your database to store the table names of your application into a byebug_dictionary.pstore file (utilizing PStore 🙌).
We then rely on the DidYouMean gem to find the closest match, update the command, and run the corrected one.
That’s it. 🤷♂
It’s worth noting that currently this plugin is not truly ORM-agnostic; to fully benefit from it, ActiveRecord is a must.
The gem is still in its infancy, and I plan to add more features in the future. If you have any suggestions, please open an issue. I hope you find it useful!
Bye bye typos 👋








