Created
May 25, 2017 02:05
-
-
Save JonathonMA/99bd034bfa3d7172400826d5cdf57ec7 to your computer and use it in GitHub Desktop.
a bad idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def bar | |
puts "bar" | |
end | |
end | |
require "did_you_mean" | |
class LuckyProxy < SimpleDelegator | |
ReallyNoMethodError = Class.new(StandardError) | |
def method_missing(meth, *args) | |
return super | |
rescue NoMethodError => e | |
corrections = DidYouMean::MethodNameChecker.new(e).corrections | |
if corrections.size == 1 | |
puts "You got lucky, assuming you did mean: #{corrections.first}" | |
send(corrections.first, *args) | |
else | |
raise ReallyNoMethodError, e.message | |
end | |
end | |
end | |
class Object | |
def ‽ | |
LuckyProxy.new(self) | |
end | |
end | |
puts "Unlucky:" | |
begin | |
Foo.new.baz | |
rescue => e | |
puts e | |
end | |
puts "Lucky:" | |
Foo.new.‽.baz |
Author
JonathonMA
commented
May 25, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment