Nope. With your example, A#riot no longer calls back to X. This is not what I
am talking to. What I mean is that in the second class 'A', def doesn't do
the same kind of thing as in in third class 'B < A', even though the *syntax
is exactly the same*. You only know that they do something different because
you look up to top of class and see '< A', then you have to say "Oh, that
means it all works different."
class A < X
def riot
print "P"
end
end
class A
def riot # this redefines
super
print "R"
end
end
class B < A # this changes how def works if method is in superclass
def riot
super # this wraps
print "W"
end
end
|It is important to understand that Ruby already has a wrapping facility
| using subclasses. And singletons act similiarly. So it would be more
| consistent to naturally extend that to in-class wraps. We can do this
| without having to add special syntax sugar (the colon).
But how? I don't see concrete syntax you are saying.
Read the following to fully understand and get syntax:
http://www.rubygarden.org/ruby?AspectOrientedRuby
But if you don't have the time right now here is a quick full example. Notice
that the defs could be in superclass or not. It makes no difference to how
wrapping works.
def w # this could be in superclass
print "W"
end
def w # and so could this
print "Y"
super
print "Y"
end
def w
print "["
superwrap
print "("
super
print ")"
end
print "]"
end
w; puts # => [Y(W)Y]
This is join-point map to help you understand above:
def a_method
# <- pre join-point
print "<"
# <- super-pre join-point
super
# <- super-post join-point
print ">"
# <- post join-point
end
Note that, if you need to BOTH redefine AND access superclass method, then you
would use redef, not def. In all other ways, this is backward compatible with
Ruby1. Please ask me any questions if something dosen't make sense.
Happy Thanksgiving, Matz,
-t0
(Do you have Thanksgiving in Japan?)