alias_method :method_missing, :method_missing_with_fix_typo end end def method_missing_with_fix_typo(name, *args) if name && method = find_method(name) $stderr.puts "WARNING: execute `#{name}` as `#{method}` for #{self}" send(method, *args) else method_missing_without_fix_typo(name, *args) end end private def find_method name name.to_s.split(//).permutation.each do |candidate| _candidate = candidate.join return _candidate if respond_to?(_candidate, true) end nil end end https://gist.github.com/1870273 Έ߹ΘͤΛશνΣοΫ
alias_method :method_missing, :method_missing_with_fix_typo end end def method_missing_with_fix_typo(name, *args) if method = find_method(name) $stdout.print "WARNING: execute `#{name}` as `#{method}`? [Y/n] " return send(method, *args) if ($stdin.getc == 'Y') end method_missing_without_fix_typo(name, *args) end private def find_method name self.class.instance_methods.each do |method| next unless method.size == name.size if(method.to_s.split(//) - name.to_s.split(//)).size == 1 return method end end end end https://gist.github.com/1883331 ͱΓ͋͑ͣͦΕͬΆ͍ͷΛฦ͢ ྻͷํ͕ྑ͍Ͱ͢Ͷ