Skip to content

Instantly share code, notes, and snippets.

@zhulik
Created October 13, 2021 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhulik/1df6b56d02b2e11f10a28e851da50cd6 to your computer and use it in GitHub Desktop.
Save zhulik/1df6b56d02b2e11f10a28e851da50cd6 to your computer and use it in GitHub Desktop.
class A
def foo
p("A::Foo")
end
alias foo1 foo
end
class B < A
def foo
p("B::Foo")
end
end
B.new.foo1 # "A::Foo is printed"
class C
def foo
p("C::Foo")
end
alias_method :foo1, :foo
end
class D < C
def foo
p("D::Foo")
end
end
D.new.foo1 # "C::Foo is printed"
require 'forwardable'
class E
extend Forwardable
def foo
p("C::Foo")
end
def_delegator :self, :foo, :foo1
end
class F < E
def foo
p("F::Foo")
end
end
F.new.foo1 # "F::Foo is printed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment