GuessMethod 0.1.1 - Now works with Rails!
It finally happened. I figured out how to get GuessMethod (particularly the GuessConstant half of things) and Rails to behave. There’s still a little kludginess to it, but they can work magic together:
mvb:~/rails/depot cms$ script/console Loading development environment. >> require 'guessmethod' => ["GuessMethod", "GuessConstant", "GuessMethodOptions", "GuessMethodGuesser", "GuessMethodOutputter"] >> LineItm.find(:first) no constant in threshold: for LineItm, sending to Object's const_missing NameError: uninitialized constant LineItm from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:266:in `load_missing_constant' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:452:in `const_missing' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:464:in `unguessed_const_missing' from /usr/local/lib/ruby/gems/1.8/gems/guessmethod-0.1.0/lib/guessmethod.rb:87:in `const_missing' from (irb):2 >> LineItem => LineItem >> LineItm.find(:first) attention: replacing non-existant constant LineItm with LineItem for Object => #<LineItem:0x30c1338 @attributes={"order_id"=>"1", "total_price"=>"3", "quantity"=>"1", "product_id"=>"8", "id"=>"1"}>
Once Rails loads a constant GuessConstant can find it, and your poor typing stops holding you back.
There’s just one thing (there’s always just one thing). Things don’t go very well if you require GuessMethod in your irbrc. You have to require it manually in the console. It works fine when script/server gets a hold of it, but not for script/console. I suppose they load everything in a different order (but this isn’t something I’ve looked into yet). Rails has to show up to the dance first.
It was this old Dr. Nic post that got me over the hurdle solving this one. Thanks Dr. Nic.
sudo gem install guessmethod
Enjoy!
Alex G said,
November 9, 2007 @ 1:20 pm
This looks very interesting from a proof of concept point of view, but I think it should never be used in production. The code you write should be valid.
Chris Shea said,
November 10, 2007 @ 1:16 am
Oh goodness no! This is definitely not for production. It’s just something for your IRB (or script/console) sessions to keep typos from slowing you down too much.