July 22, 2007 at 12:58 pm
· Filed under Guess Method, Ruby
Another release of GuessMethod, the aggressive spell checker for irb!
GuessMethod now handles constants as well, giving you the opportunity for even more non-fatal typos. Prepare for yourself for this magic:
003:0> Strin.tos
attention: replacing non-existant constant Strin with String for Object
attention: sending to_s instead of tos to String:Class
"String"
Enjoy!
Permalink
July 19, 2007 at 2:28 pm
· Filed under Guess Method, Ruby
I am pleased to announce the initial release of GuessMethod (as demonstrated earlier here).
GuessMethod is an aggressive spell checker for irb. It is not for production.
Get it:
sudo gem install guessmethod
Its sole requirement is HighLine.
Thanks to Dr. Nic for telling me to release it and for newgem.
Enjoy!
Permalink
July 17, 2007 at 7:53 pm
· Filed under Guess Method, Ruby, irb
GuessMethod is probably a bad idea:
mvb:~ cms$ irb
001:0> load 'mm.rb'
true
002:0> class Object; include GuessMethod; end
Object
003:0> ['1', '2', '3'].mp {|x| x.toi}
attention: sending map instead of mp to ["1", "2", "3"]:Array
attention: sending to_i instead of toi to "1":String
attention: sending to_i instead of toi to "2":String
attention: sending to_i instead of toi to "3":String
[1, 2, 3]
004:0> ['1','2','3'].mp {|x| x.to_}
attention: sending map instead of mp to ["1", "2", "3"]:Array
ambiguous method to_, possible matches to_a, to_i, to_s, to_f for "1":String
NoMethodError: undefined method `to_' for "1":String
from ./mm.rb:9:in `old_method_missing'
from ./mm.rb:34:in `method_missing'
from (irb):4
from ./mm.rb:25:in `map'
from ./mm.rb:25:in `send'
from ./mm.rb:25:in `method_missing'
from (irb):4
from (irb):3
005:0> eixt
attention: sending exit instead of eixt to main:Object
13 seconds
mvb:~ cms$
It’s using the method_missing pre-handling trick I talked about earlier. It’s nasty. I’m not actually actively using this, but I’ve enjoyed toying around with it.
You can see after line 4 that the ambiguous ‘to_’ gets passed on to String’s method_missing, which would be cool if String had a method_missing that did something interesting. But this is a bad idea anyway. The whole thing is one giant bad idea.
Permalink