Dr Nic

Magic Wiggly Lines => GuessMethod, by Chris Shea

If you ever make time to code just for pleasure, then method_missing and const_missing are just begging for abuse.

Chris Shea has come up with GuessMethod – a very cool hack that now deprecates my concept of Magic Wiggly Linesa spell-checker for runtime code.

What’s it do? Cop a squiz at this genius…

$ gem install guessmethod -y
$ irb
> require 'rubygems'
> require 'guessmethod'
> class Object; include GuessMethod; end  # though this could go in the guessmethod.rb file in the gem
> class Product; def name; "Some product"; end; end
> Prodct.nw.nae
attention: replacing non-existant constant Prodct with Product for Object
attention: sending new instead of nw to Product:Class
attention: sending name instead of nae to #<Product:0x144ff10>:Product
=> "Some product"

That’s going straight into my .irbrc file. My bad spelling, coupled with my British/Australian English, will never slow me down again!

UPDATE: actually, it doesn’t like being in the .irbrc file for Rails console; so in the config/environments/development.rb files will have to do for the moment.

Related posts:

  1. Find objects in IRB directly from browser URLs A long time ago, I tired of going into the...
  2. Dr Nic’s Magic Show at RejectConf2007 Update: there is a patch available for edge rails to...
  3. Magic Multi-Connections: A “facility in Rails to talk to more than one database at a time” At this point in time there’s no facility in Rails...
  4. Spring Collection – the Modular Magic Models Dr Nic’s Magic Models are like cheating on your taxes...
  5. Meta-Magic in Ruby: Dr Nic Unplugged in Stockholm Last nights’ Ruby meeting in Stockholm had a great turn...

11 Responses to “Magic Wiggly Lines => GuessMethod, by Chris Shea”

  1. mlangenberg says:

    Ah, great for all those quick, frustrating typo’s I’m making in irb.

  2. Mislav says:

    Haha :) Talk about the principle of least surprise …

  3. Eric Mill says:

    All right – awesome.

  4. mlangenberg says:

    Be warned, it’s borking Rails’ routing behaviour:

    “no constant in threshold: for ArticlesController, sending to Object’s const_missing”

  5. Awesome. I do something very similar in my text-replacement program here:


    Now, if the text snippit file isn’t found, it simply replaces the input with the first suggestion of the spellcheck. Useful in apps with no spellchecking, or when you *know* you are going to spell that word wrong.

  6. Chris Shea says:

    @mlangenberg [via] – Yep. I guess I’m going to have to work a little harder to make sure Rails and co. aren’t getting ruined.

  7. Jerrett says:

    I really would suggest NOT putting it in development.rb, if you must use it :)

    Do you really want to find out you made weird typos in your code, only after it goes live?

  8. Dr Nic says:

    @Jerrett [via] – curse you spoiling my fun :P

  9. [...] Dr Nic » Magic Wiggly Lines => GuessMethod, by Chris Shea (tags: rails) [...]

  10. [...] Meta-Magic in Rails: Become a Master Magician Dr. Nic put on a great show explaining Ruby meta-programming, stressing that introspection is the ability to look at your own code, while reflection is the ability to change your on code dynamically. He also compared Perl to a puppy (fun, but with no understanding of itself), Java to Keith Richards (not so cute anymore) and Rails to Neo (knows about and can change his environment). Finally, the good doctor demonstrated a quite useless, though fun, plugin he had created written by Chris Shea; guessmethod, which attempts to catch and correct misspelled contant and method names dynamically. Download notes [...]

  11. [...] Magic Wiggly Lines => GuessMethod, by Chris Shea [...]