Forum: IronRuby ScriptScope.SetVariable - pass in a function

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.
3a6fa82776b1210043b28ae6872e0451?d=identicon&s=25 Benjamin van der Veen (bvanderveen)
on 2008-11-16 02:56
Hi,

I'd like do something like this:

public void AddFunction() {
    aScriptScope.SetVariable("my_function", (Action<string>)MyFunction);
}

public void MyFunction(string value) {
    // do stuff!
}

Currently if I execute a script like "my_function 'hello!'" or
"my_function('hello!')" I get:

ArgumentException: wrong number or type of arguments for `my_function'

Ideas? If I can, I'd like to declare the class which contains these
methods 'internal'.

Thanks so much!
benjamin
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2008-11-16 03:11
(Received via mailing list)
Try my_function.invoke('hello!'). Ruby doesn't have first class methods.
For convenience we can monkey-patch Delegate to mimic procs (add [],
call methods).

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