# Executing javascript from Ruby

**URL:** <https://www.ruby-forum.com/t/executing-javascript-from-ruby/138527>\
**Category:** Ruby\
**Created:** [May 24, 2008, 12:47am UTC](https://www.ruby-forum.com/t/executing-javascript-from-ruby/138527 "2008-05-24T00:47:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 24, 2008, 12:47am UTC](https://www.ruby-forum.com/t/executing-javascript-from-ruby/138527/1 "2008-05-24T00:47:56Z")

</div>

I need to execute a javascript from Ruby. The result of the javascript  
is a URL. I could not find anything that help bridge the gap between  
javascript and Ruby. Does anyone know if there is something that I can  
use for this problem? TIA.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 24, 2008, 1:24am UTC](https://www.ruby-forum.com/t/executing-javascript-from-ruby/138527/2 "2008-05-24T01:24:55Z")

</div>

-------- Original-Nachricht --------

> Datum: Sat, 24 May 2008 07:45:00 +0900  
> Von: “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: removed\_email\_address@domain.invalid  
> Betreff: Executing javascript from Ruby

> I need to execute a javascript from Ruby. The result of the javascript  
> is a URL. I could not find anything that help bridge the gap between  
> javascript and Ruby. Does anyone know if there is something that I can  
> use for this problem? TIA.

Hi —

do you want to open the URL in Ruby ?  
There are many possibilities: look eg. here:

[http://www.juretta.com/log/2006/08/13/ruby\_net\_http\_and\_open-uri/](http://www.juretta.com/log/2006/08/13/ruby_net_http_and_open-uri/)

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 26, 2008, 8:14pm UTC](https://www.ruby-forum.com/t/executing-javascript-from-ruby/138527/3 "2008-05-26T20:14:44Z")

</div>

On Sat, May 24, 2008 at 07:45:00AM +0900, removed\_email\_address@domain.invalid wrote:

> I need to execute a javascript from Ruby. The result of the javascript  
> is a URL. I could not find anything that help bridge the gap between  
> javascript and Ruby. Does anyone know if there is something that I can  
> use for this problem? TIA.

Yes… Johnson bridges Ruby to JavaScript. We haven’t released a gem  
yet, but you can check it out from github now. Its pretty stable, and  
we only have 1 bug blocking our release. 🙂

[GitHub - jbarnette/johnson: Johnson wraps JavaScript in a loving Ruby embrace.](http://github.com/jbarnette/johnson/tree/master)

Example:

context = Johnson::Context.new  
context.evaluate(“function foo() { return ‘hello world’; }”)  
context.evaluate(“foo()”) # =\> ‘hello world’
