# Passing a callback to ScriptObject.Invoke

**URL:** <https://www.ruby-forum.com/t/passing-a-callback-to-scriptobject-invoke/146597>\
**Category:** IronRuby\
**Created:** [August 22, 2008, 8:07pm UTC](https://www.ruby-forum.com/t/passing-a-callback-to-scriptobject-invoke/146597 "2008-08-22T20:07:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean\_CSHess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@Sean\_CSHess](https://www.ruby-forum.com/u/Sean_CSHess)\
**Post date:** [August 22, 2008, 8:07pm UTC](https://www.ruby-forum.com/t/passing-a-callback-to-scriptobject-invoke/146597/1 "2008-08-22T20:07:09Z")

</div>

Hi everybody,  
I’m plugging in to an existing javascript library using invoke. I can  
successfully call my\_js\_object.invoke and get it to call different  
functions.

They implemented a function called Observe that accepts a callback  
(event  
system). How can I tie in to javascript events with ruby? I can pass  
values, like js\_object.invoke “Observe”,“EventName”, but it doesn’t  
really  
work to put a block as the last (the callback) parameter.

Any ideas? How can I do this?

Thanks  
~sean

---

<div class="post-metadata">

**Author:** ![Sean\_CSHess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@Sean\_CSHess](https://www.ruby-forum.com/u/Sean_CSHess)\
**Post date:** [August 22, 2008, 10:24pm UTC](https://www.ruby-forum.com/t/passing-a-callback-to-scriptobject-invoke/146597/2 "2008-08-22T22:24:55Z")

</div>

sure, I’ll cook one up really quick

On Fri, Aug 22, 2008 at 2:21 PM, Tomas M. \<

---

<div class="post-metadata">

**Author:** ![Sean\_CSHess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@Sean\_CSHess](https://www.ruby-forum.com/u/Sean_CSHess)\
**Post date:** [August 22, 2008, 10:23pm UTC](https://www.ruby-forum.com/t/passing-a-callback-to-scriptobject-invoke/146597/3 "2008-08-22T22:23:09Z")

</div>

Can you send a small example of what you’re trying to do? Is it browser  
native JavaScript or managed DLR JScript?

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Sean C.  
Hess  
Sent: Friday, August 22, 2008 11:06 AM  
To: removed\_email\_address@domain.invalid  
Subject: [Ironruby-core] Passing a callback to ScriptObject.Invoke

Hi everybody,

I’m plugging in to an existing javascript library using invoke. I can  
successfully call my\_js\_object.invoke and get it to call different  
functions.

They implemented a function called Observe that accepts a callback  
(event system). How can I tie in to javascript events with ruby? I can  
pass values, like js\_object.invoke “Observe”,“EventName”, but it doesn’t  
really work to put a block as the last (the callback) parameter.

Any ideas? How can I do this?

Thanks  
~sean

---

<div class="post-metadata">

**Author:** ![Sean\_CSHess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@Sean\_CSHess](https://www.ruby-forum.com/u/Sean_CSHess)\
**Post date:** [August 22, 2008, 10:43pm UTC](https://www.ruby-forum.com/t/passing-a-callback-to-scriptobject-invoke/146597/4 "2008-08-22T22:43:40Z")

</div>

Ok, I put the following in index.html in a blank ruby dynamic  
silverlight  
project

[http://pastie.textmate.org/258247](http://pastie.textmate.org/258247)

This is a really simple event system, with only one event, one  
listener…  
etc. It has a default handler you can trigger by clicking the link.

Then, here is app.rb

[http://pastie.textmate.org/258249](http://pastie.textmate.org/258249)

Uncomment line 10 to see that you have a handle on the js object. Line  
11,  
however, throws an error no matter what I do.

Basically, I want to be able to pass a block of ruby code to be executed  
whenever the javascript function is called.

I know I can use the HTML stuff to listen for a click directly, but I’m  
trying to plug into a js system that dispatches events this way, so I  
can’t  
change the js interface.

Thanks for your help, and let me know if you have any more questions.

~sean

---

<div class="post-metadata">

**Author:** ![Sean\_CSHess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@Sean\_CSHess](https://www.ruby-forum.com/u/Sean_CSHess)\
**Post date:** [August 26, 2008, 1:33am UTC](https://www.ruby-forum.com/t/passing-a-callback-to-scriptobject-invoke/146597/5 "2008-08-26T01:33:20Z")

</div>

Sean, Iâ€™ll make sure to get back to you. I can run a ruby block given a  
Javascript event, but Iâ€™ll cook up a app that does what you ask shortly.  
Let me know if this is urgent, and Iâ€™ll do it faster =)

On 8/22/08 1:42 PM, “Sean C. Hess” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

Ok, I put the following in index.html in a blank ruby dynamic  
silverlight project

[http://pastie.textmate.org/258247](http://pastie.textmate.org/258247)

This is a really simple event system, with only one event, one  
listener… etc. It has a default handler you can trigger by clicking  
the link.

Then, here is app.rb

[http://pastie.textmate.org/258249](http://pastie.textmate.org/258249)

Uncomment line 10 to see that you have a handle on the js object. Line  
11, however, throws an error no matter what I do.

Basically, I want to be able to pass a block of ruby code to be executed  
whenever the javascript function is called.

I know I can use the HTML stuff to listen for a click directly, but I’m  
trying to plug into a js system that dispatches events this way, so I  
can’t change the js interface.

Thanks for your help, and let me know if you have any more questions.

~sean

On Fri, Aug 22, 2008 at 2:23 PM, Sean C. Hess [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
sure, I’ll cook one up really quick

On Fri, Aug 22, 2008 at 2:21 PM, Tomas M.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
Can you send a small example of what you’re trying to do? Is it browser  
native JavaScript or managed DLR JScript?

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Sean C.  
Hess  
Sent: Friday, August 22, 2008 11:06 AM  
To: removed\_email\_address@domain.invalid  
Subject: [Ironruby-core] Passing a callback to ScriptObject.Invoke

Hi everybody,

I’m plugging in to an existing javascript library using invoke. I can  
successfully call my\_js\_object.invoke and get it to call different  
functions.

They implemented a function called Observe that accepts a callback  
(event system). How can I tie in to javascript events with ruby? I can  
pass values, like js\_object.invoke “Observe”,“EventName”, but it doesn’t  
really work to put a block as the last (the callback) parameter.

Any ideas? How can I do this?

Thanks

~sean

---

<div class="post-metadata">

**Author:** ![Sean\_CSHess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@Sean\_CSHess](https://www.ruby-forum.com/u/Sean_CSHess)\
**Post date:** [August 26, 2008, 3:42am UTC](https://www.ruby-forum.com/t/passing-a-callback-to-scriptobject-invoke/146597/6 "2008-08-26T03:42:37Z")

</div>

Really? That would be awesome. Realize though, that I need it to work  
for custom callbacks, not for any standard ha event.

Thanks! Yeah, we kind if tabled the project because it was taking so  
long, but I’d love to know the answer  
On Aug 25, 2008, at 5:32 PM, Jimmy S.  
\<removed\_email\_address@domain.invalid
