Skip to content

Instantly share code, notes, and snippets.

@pasberth
Created November 6, 2011 03:10
Show Gist options
  • Select an option

  • Save pasberth/1342407 to your computer and use it in GitHub Desktop.

Select an option

Save pasberth/1342407 to your computer and use it in GitHub Desktop.
typoを検出するッ
# -*- coding: utf-8 -*-
module Kernel
alias typofixer_original_method_missing method_missing
def method_missing funcname, *args, &blk
at = caller
begin
typofixer_original_method_missing funcname, *args, &blk
rescue NoMethodError, NameError => e
funcname = funcname.to_s
(methods + private_methods).each do |my_method|
my_method = my_method.to_s
if (funcname.length / 2) < (0..funcname.length).inject(0) { |r, i| funcname[i] == my_method[i] ? r + 1 : r }
puts "もしかして: #{my_method}"
puts at
return send my_method, *args, &blk
end
end
raise e
end
end
end
clane # => もしかして: clone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment