T
Trans
Any chance Ruby 1.9 will have before, after and around method
composition support?
T.
composition support?
T.
Hi,
In message "Re: before, after and around Ruby 1.9"
|Any chance Ruby 1.9 will have before, after and around method
|composition support?
No. Wait for 2.0 for built-in method combination. The vague plan is
making open-class to stack methods on the current ones, unless
explicitly removed, i.e.
class Foo < Object
def foo
puts "Foo#foo (1)"
end
end
class Foo # re-open
def foo
super # calls the first foo
puts "Foo#foo (2)"
end
end
will print
Foo#foo (1)
Foo#foo (2)
No alias required.
This works as "around". And "before" and "after" can be rewritten
using "around". Note that this is not a fixed idea at all.
matz.
Hi,
In message "Re: before, after and around Ruby 1.9"
|Any chance Ruby 1.9 will have before, after and around method
|composition support?
No. Wait for 2.0 for built-in method combination. The vague plan is
making open-class to stack methods on the current ones, unless
explicitly removed, i.e.
class Foo < Object
def foo
puts "Foo#foo (1)"
end
end
class Foo # re-open
def foo
super # calls the first foo
puts "Foo#foo (2)"
end
end
will print
Foo#foo (1)
Foo#foo (2)
No alias required.
This works as "around". And "before" and "after" can be rewritten
using "around". Note that this is not a fixed idea at all.
Hi,
In message "Re: before, after and around Ruby 1.9"
|Any chance Ruby 1.9 will have before, after and around method
|composition support?
No. Wait for 2.0 for built-in method combination. The vague plan is
making open-class to stack methods on the current ones, unless
explicitly removed, i.e.
class Foo < Object
def foo
puts "Foo#foo (1)"
end
end
class Foo # re-open
def foo
super # calls the first foo
puts "Foo#foo (2)"
end
end
will print
Foo#foo (1)
Foo#foo (2)
No alias required.
This works as "around". And "before" and "after" can be rewritten
using "around". Note that this is not a fixed idea at all.
matz.
2007/9/8 said:Just to try to crystalize my own thoughts about this in general. I'm
concerned that because of the dynamic nature of "assembling" the
pieces of a Ruby program, some of these proposals might lead to
indeterminate (or at best mysterious) results because of the
difficulties in figuring out the order of code parsing/execution. (...)
Rick, I don't see a way to solve this problem. If you add around
methods to an existing method, the order in which you do this is
always important, regardless of the syntax or the implementation,
isn't it?
2007/9/11 said:Yes, my concern is that because there's been so much clever use of
dynamic loading of code in Ruby, and particularly in Rails, that such
constructs might lead to bedlam.
And at least I think that it's an argument for not repurposing super
which has a meaning which depends strictly on the class
inheritance/module inclusion chain and not on how that chain happened
to get to a particular state.
The module inclusion chain is already dependent on the sequence in
which the code is executed, especially if you use super. What I like
about Matz's proposal is that there is still only one of these chains
and one way to walk them: super. Having a different way to call the
next method would make things more complicated, IMO.
Rick said:Here's the sequence dependency I'm concerned about.
class A
def m
puts "Hi from A"
end
end
class B < A
def m
puts "And now a wird from my superclass.!"
super
end
class B < A
#fix the typo
def m
puts "And now a word from my superclass!"
end
end
B.new.m
With the current semantics, this will produce:
And now a word from my superclass!
Hi from A
whereas Matz' proposal would produce:
And now a wird from my superclass!
And now a word from my superclass!
Hi from A
How do you REPLACE a method implementation which invokes super in this
brave new world?
Here's the sequence dependency I'm concerned about.
class A
def m
puts "Hi from A"
end
end
class B < A
def m
puts "And now a wird from my superclass.!"
super
end
class B < A
#fix the typo
def m
puts "And now a word from my superclass!"
end
end
B.new.m
With the current semantics, this will produce:
And now a word from my superclass!
Hi from A
whereas Matz' proposal would produce:
And now a wird from my superclass!
And now a word from my superclass!
Hi from A
How do you REPLACE a method implementation which invokes super in this
brave new world?
Here's the sequence dependency I'm concerned about.
class A
def m
puts "Hi from A"
end
end
class B < A
def m
puts "And now a wird from my superclass.!"
super
end
class B < A
#fix the typo
def m
puts "And now a word from my superclass!"
end
end
B.new.m
With the current semantics, this will produce:
And now a word from my superclass!
Hi from A
whereas Matz' proposal would produce:
And now a wird from my superclass!
And now a word from my superclass!
Hi from A
How do you REPLACE a method implementation which invokes super in this
brave new world?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.