About mixins and traits in ruby
Julian Fitzell
julian at beta4.com
Mon Feb 16 09:25:28 UTC 2004
ducasse wrote:
> Something that I could not find in the book (not really a good one)
> can you in a mixin invoke an overridden method using super? One person
> told me yes but it is not a trustable source :)
Well, ruby inserts the module into the ancestry between the class that
includes it and its superclass. So for example:
julian@[cable]:julian$ cat test.rb
module A
def foo
puts "foo in A"
super
end
end
class B
def foo
puts "foo in B"
end
end
class C < B
include A
def foo
puts "foo in C"
super
end
end
C.new.foo
julian@[cable]:julian$ ruby test.rb
foo in C
foo in A
foo in B
Julian
More information about the Squeak-dev
mailing list
|