E
Eric Mahurin
Here is a pure ruby soluntion to doing AOP. You just need one
little method from evil.rb: Object#become. sub-classing and
then having the parent "become" the child is very similar to
the proposed "cut" (not sure about some of the management
facilities). Anyways, as soon as you require 'evil.rb' you
pretty much have it. You can get evil.rb here:
http://rubyforge.org/cgi-bin/viewcvs.cgi/evil/lib/evil.rb?cvsroot=3Devil
Here is a demo using this to get AOP:
require 'evil'
class A
def foo;"A";end
end
a =3D A.new
a.foo # =3D> "A"
# first level "cut"
class B < A.clone # need a clone to prevent a loop
def foo;"["+super+"]";end
end
A.become(B) # replace parent with subclass
a.foo # =3D> "[A]"
# second level "cut"
class C < A.clone
def foo;"{"+super+"}";end
end
A.become(C)
a.foo # =3D> "{[A]}"
# restore the original functionality
A.become(B.superclass)
a.foo # =3D> "A"
module Brackets
def foo;"["+super+"]";end
end
# "preclude"-like functionality
class D < A.clone
include Brackets
end
A.become(D)
a.foo # =3D> "[A]"
Of course if we had this, it would be better to have a safer
Class#replace and that be able to break circular loops
automatically instead of having to use #clone to break the loop
manually.
=09
__________________________________=20
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com
little method from evil.rb: Object#become. sub-classing and
then having the parent "become" the child is very similar to
the proposed "cut" (not sure about some of the management
facilities). Anyways, as soon as you require 'evil.rb' you
pretty much have it. You can get evil.rb here:
http://rubyforge.org/cgi-bin/viewcvs.cgi/evil/lib/evil.rb?cvsroot=3Devil
Here is a demo using this to get AOP:
require 'evil'
class A
def foo;"A";end
end
a =3D A.new
a.foo # =3D> "A"
# first level "cut"
class B < A.clone # need a clone to prevent a loop
def foo;"["+super+"]";end
end
A.become(B) # replace parent with subclass
a.foo # =3D> "[A]"
# second level "cut"
class C < A.clone
def foo;"{"+super+"}";end
end
A.become(C)
a.foo # =3D> "{[A]}"
# restore the original functionality
A.become(B.superclass)
a.foo # =3D> "A"
module Brackets
def foo;"["+super+"]";end
end
# "preclude"-like functionality
class D < A.clone
include Brackets
end
A.become(D)
a.foo # =3D> "[A]"
Of course if we had this, it would be better to have a safer
Class#replace and that be able to break circular loops
automatically instead of having to use #clone to break the loop
manually.
=09
__________________________________=20
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com