[Ironruby-core] Delegates (agian)

Paulo Köch paulo.koch at gmail.com
Thu Oct 25 18:09:11 EDT 2007


x << C.instance_method(:y).bind(obj)

this piece of code does not add any method to anyone. It just passes
C's implementation of method "y" bound to object "obj" as an argument
to object "x"'s "<<" method. No method adding, just indirection.

On 10/25/07, Dermot Hogan <lists at ruby-forum.com> wrote:
> > I don't think we need RubyDelegate, you can write
> >
> > x << method(:y)
> > x << C.instance_method(:y).bind(obj)
> >
> > or
> >
> > x += method(:y)
> > x += C.instance_method(:y).bind(obj)
> > x -= method(:y)
> >
> > if you will.
> >
> > Blocks/procs should also work:
> >
> > x { puts 'on click' }
> > x << lambda { puts 'on click' }
> >
> > Tomas
>
> This isn't really what I mean. You need to be able to provide
> *syntactically* a delegate reference.
>
> So in C#, we have x += new EventHandler(mymethod)
>
> and in VB (I'm a bit rusty but something like this):
>
> x += new EventHandler(AddressOf mymethod)
>
> it's not the same as adding a method to an object. The object already
> *has* the method. What you need to to do is add the *delegate* (a
> typesafe function pointer) into the delegate chain.
>
> I'm not an expert in any way in what you are doing in the DLR, but it
> doesn't seem to me that this does it. A delegate is a different thing
> from a method object. 'method' returns a method object which isn't the
> same as a delegate (an instance of the Delegate class) - at least, I
> can't add it into the delegate chain with the current version of IR.
>
>
> Are you saying that 'method' will return a delegate? I'm not clear on
> this at all.
>
>
>
> Dermot
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>


More information about the Ironruby-core mailing list