Skip to content

Instantly share code, notes, and snippets.

@nordringrayhide
Created March 16, 2012 06:32
Show Gist options
  • Save nordringrayhide/2048790 to your computer and use it in GitHub Desktop.
Save nordringrayhide/2048790 to your computer and use it in GitHub Desktop.
super instead alias_method_chain
class A
def foo
puts 'A#foo'
end
end
class B < A
def foo
super
puts 'B#foo'
end
end
B.new.foo
=> A#foo
=> B#foo
--- #2
module A
def foo
puts 'A#foo'
end
end
class B
include A
def foo
super
puts 'B#foo'
end
end
B.new.foo
=> A#foo
=> B#foo
-- #3
module A
def foo
puts 'A#foo'
end
end
module B
def foo
puts 'B#foo'
end
end
class C
include B
include A
end
C.new.foo
puts "foo method owner is #{ C.new.method(:foo).owner.inspect }"
B#foo
foo method owner is B
-- #4
module A
def foo
puts 'A#foo'
end
end
module B
def foo
puts 'B#foo'
end
end
class C
include B
include A
def foo
super
puts 'C#foo'
end
end
C.new.foo
=> A#foo
=> C#foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment