Forum: IronRuby An Issue with CLR Delegates

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F0f461459193aa098a80bd3e74e0ac9c?d=identicon&s=25 Shay Friedman (shayfriedman)
on 2009-06-09 14:34
Hi,

Today I'm playing with CLR delegates :)

I've run into a strange behavior.

Take a look at the next C# block:
-----------
public class Printer
{
  public delegate void PrintValue(string value);
}
-----------

Assuming the above is the content of assembly.dll, take a look at the
next IR console output:

-----------
>>> require "assembly.dll"
=> true
>>> p = Printer::PrintValue.new { |x| puts x }
=> Printer+PrintValue
>>> p("dsfs")
"dsfs"
=> nil
>>> d = Printer::PrintValue.new { |x| puts x }
=> Printer+PrintValue
>>> d("dsfd")
:0: undefined method `d' for main:Object (NoMethodError)
------------

Why does p work and d doesn't?

BTW, I see that delegates are converted to something called LightLambda.
What is that?

Many thanks!
Shay.
----------------------------
http://www.ironshay.com
Follow me: http://twitter.com/ironshay
Ade8632553a9243ae05fc920f68644c1?d=identicon&s=25 Jim Deville (Guest)
on 2009-06-09 19:32
(Received via mailing list)
Looks like some odd caching or invalidation. Please file a bug on
Codeplex.

JD

...there is no try
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2009-06-09 20:58
(Received via mailing list)
This is actually correct behavior.

p("dsfs") calls Kernel#p with parameter "dsfs"
d("dsfs") attempts to call method "d", which doesn't exist.

You need to do p.invoke("dsfs") and d.invoke("dsfs") to invoke the
delegates.

Tomas
F0f461459193aa098a80bd3e74e0ac9c?d=identicon&s=25 Shay Friedman (shayfriedman)
on 2009-06-09 22:07
lol!

Brilliant discovery Tomas!

Thanks!
----------------------------
http://www.ironshay.com
Follow me: http://twitter.com/ironshay
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2009-06-09 22:26
(Received via mailing list)
Well, it doesn't take much to see these things right away. Just to
implement a Ruby VM :)

Tomas
This topic is locked and can not be replied to.