# ScriptScope.SetVariable - pass in a function

**URL:** <https://www.ruby-forum.com/t/scriptscope-setvariable-pass-in-a-function/153385>\
**Category:** IronRuby\
**Created:** [November 16, 2008, 2:56am UTC](https://www.ruby-forum.com/t/scriptscope-setvariable-pass-in-a-function/153385 "2008-11-16T02:56:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bvanderveen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed655f/32.png) [@bvanderveen](https://www.ruby-forum.com/u/bvanderveen)\
**Post date:** [November 16, 2008, 2:56am UTC](https://www.ruby-forum.com/t/scriptscope-setvariable-pass-in-a-function/153385/1 "2008-11-16T02:56:03Z")

</div>

Hi,

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!  
benjamin

---

<div class="post-metadata">

**Author:** ![bvanderveen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed655f/32.png) [@bvanderveen](https://www.ruby-forum.com/u/bvanderveen)\
**Post date:** [November 16, 2008, 3:11am UTC](https://www.ruby-forum.com/t/scriptscope-setvariable-pass-in-a-function/153385/2 "2008-11-16T03:11:27Z")

</div>

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
