Guess Method

Get Version

0.2.1

→ ‘guessmethod’

What

GuessMethod is an aggressive spell checker for irb… and rake! Don’t let sloppy typing slow you down. Let GuessMethod take care of you.

Throw require 'guessmethod' in your .irbrc for the GuessMethod magic.

Try require 'guessmethod/rake' in your rakefiles or use the new grake command for GuessRakeTask magic. But BE CAREFUL!

How

GuessMethod aliases out method_missing and const_missing and replaces it with a version that tries to find a close match for your possibly mistyped method or constant. You can see that GuessMethod has already outgrown its name.

When GuessMethod can’t figure anything out, it lets the original method_missing or const_missing handle the problem.

GuessRakeTask works along similar lines.

Installing

sudo gem install guessmethod

Demonstration of usage

001:0> require 'rubygems'
true
002:0> require 'guessmethod'
true
003:0> Stirng.tos
attention: replacing non-existant constant Stirng with String for Object
attention: sending to_s instead of tos to String:Class
"String" 
004:0> ['1','2','3'].mp {|x| x.tof}
attention: sending map instead of mp to ["1", "2", "3"]:Array
attention: sending to_f instead of tof to "1":String
attention: sending to_f instead of tof to "2":String
attention: sending to_f instead of tof to "3":String
[1.0, 2.0, 3.0]
005:0> eixt
attention: sending exit instead of eixt to main:Object

Or, see the magic of grake:

mvb:~/hot-rails-app cms$ grake db:migrat 
(in /Users/cms/hot-rails-app)
attention: invoking task db:migrate instead of db:migrat
...

There are a number of options available which affect how GuessMethod works.

How to submit patches

You can submit patches through the RubyForge page for guessmethod.

You can check out guessmethod from the svn repository at http://code.tie-rack.org/cms/guessmethod/.

Read the 8 steps for fixing other people’s code

GuessMethod and Rails

If you’re trying to have GuessMethod in your .irbrc (like me), but not have it get in the way of Rails when doing local testing, instead of a normal require 'guessmethod', do this:

IRB.conf[:IRB_RC] = Proc.new { require 'guessmethod' }

That will ensure that GuessMethod shows up after Rails does all its magic when you start a script/console session.

License

This code is free to use under the terms of the MIT license.

Contact

Comments are welcome. Send an email to chris @@ tie-rack .. org.

website generated via Dr Nic's newgem, on 28th March 2008
Theme extended from Paul Battley