ScriptScope.SetVariable - pass in a function


I’d like do something like this:

public void AddFunction() {
aScriptScope.SetVariable(“my_function”, (Action)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!

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs