Skip to content

Instantly share code, notes, and snippets.

@meltingice
Last active July 28, 2016 17:09
Show Gist options
  • Save meltingice/08467d716ad7f0ec160530d8f36968a2 to your computer and use it in GitHub Desktop.
Save meltingice/08467d716ad7f0ec160530d8f36968a2 to your computer and use it in GitHub Desktop.
# 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