Last active
July 28, 2016 17:09
-
-
Save meltingice/08467d716ad7f0ec160530d8f36968a2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Is there a better way to achieve this without having to define #orig_foo in each subclass? | |
class A | |
def orig_foo | |
self.class.superclass == Object ? foo : method(:foo).super_method.call | |
end | |
def foo | |
"foo" | |
end | |
end | |
class B < A | |
def foo | |
"bar" | |
end | |
end | |
A.new.foo #=> "foo" | |
B.new.foo #=> "bar" | |
A.new.orig_foo #=> "foo" | |
B.new.orig_foo #=> "foo" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment