[Ironruby-core] Delegates (agian)

Dermot Hogan lists at ruby-forum.com
Thu Oct 25 18:16:21 EDT 2007

Charles Oliver Nutter wrote:
> Dermot Hogan wrote:
>> equivalent '>>' (though I suppose you could define one). Anyway, you
>> have to be able to remove a delegate as well as add one.
> A problem you've missed here is that x += y and x -= y are (always)
> equivalent in Ruby to x = x + y and x = x - y. Unless + or - mutate the
> original object, now mutation will occur.

In .NET C# etc, the += and -= for delegates don't really mean the same 
as they do in other contexts. They means 'add/remove' a delegate 
into/from the delegate queue. You can't say

x = new EventHandler(mymethod)

all you can do is add/remove. It's another example of syntactic kluging 
IMO. It does work well in practise, though.

> Thoughts? We've had similar questions about how to handle event listener
> registration in JRuby, though there's no legacy operator syntax to
> support in our case.

Yes - I suppose so. You still have to add the address of the listener 
into the system in some way. Similar problem, but I think delegates are 
a bit trickier - they aren't just function pointers; they carry other 
information as well. All .NET languages seem to treat them specially.


Posted via http://www.ruby-forum.com/.

More information about the Ironruby-core mailing list