Forum: IronRuby ScriptScope.SetVariable - pass in a function

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Benjamin v. (Guest)
on 2008-11-16 03:56

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!
Tomas M. (Guest)
on 2008-11-16 04: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).

This topic is locked and can not be replied to.