Skip to content

Add IRB fix command to rerun with corrected spelling (fixes #179)#204

Open
krsinghshubham wants to merge 2 commits intoruby:masterfrom
krsinghshubham:irb-fix-command
Open

Add IRB fix command to rerun with corrected spelling (fixes #179)#204
krsinghshubham wants to merge 2 commits intoruby:masterfrom
krsinghshubham:irb-fix-command

Conversation

@krsinghshubham
Copy link

@krsinghshubham krsinghshubham commented Feb 18, 2026

Summary

Implements the feature requested in #179: when using IRB, after a typo triggers a "Did you mean?" error, users can type fix to rerun the previous command with the suggested correction applied. This is similar to thefuck.

Example

irb(main):001> 1.zeor?
# => NoMethodError (undefined method `zeor?' for 1:Integer)
#    Did you mean?  zero?

irb(main):002> fix
# Rerunning with: 1.zero?
# => true

Implementation Details

Architecture

  • lib/did_you_mean/irb.rb – Core module with LastError, FixCommand, and MAX_EDIT_DISTANCE = 2
  • lib/did_you_mean/irb/eval_patch.rb – Patches IRB::Irb#eval_input to capture correctable exceptions
  • lib/did_you_mean/irb/command.rb – Registers the fix command with IRB

Supported Error Types

NoMethodError, NameError, KeyError, NoMatchingPatternKeyError, LoadError

Correction Logic

  • Single suggestion only (edit distance ≤ 2)
  • Replacement patterns: identifiers, symbols, strings
  • Clear user feedback when fix cannot be applied
  • Discoverability hint: "Type fix to rerun with the correction." when fix is available
  • dym alias for users who use fix as a variable

Changes

  • lib/did_you_mean/irb.rb, eval_patch.rb, command.rb
  • lib/did_you_mean.rb – auto-requires IRB extension
  • README.md – documentation

Fixes #179


krsinghshubham and others added 2 commits February 19, 2026 01:37
…uby#179)

- Add fix command that reruns the previous command with Did you mean? correction
- Only applies when exactly one suggestion exists with edit distance <= 2
- Supports NoMethodError, NameError, KeyError, LoadError, NoMatchingPatternKeyError
- Auto-loads when IRB is used
- Document in README
- Show 'Type `fix` to rerun with the correction.' when fix is available
- Add dym alias for users who use fix as a variable
- Document naming conflict and dym alternative in README

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rerun the previous command with corrected spelling in irb.

1 participant