Activate your free membership today | Log-in

Thursday, March 27th, 2008

HotRuby: Run Ruby on a JavaScript interpreter?

Category: JavaScript, Library, Ruby, Showcase

This is from the "wow, really?" department. HotRuby is an implementation of Ruby in JavaScript!

The way it works is that a HotRuby "VM" takes the resulting output from YARV and can grok it via JSON:

RUBY:
    VM::InstructionSequence.compile(cgi['src'], "src", 1, OutputCompileOption).to_a.to_json

Thus, you can embed Ruby by doing something like this:

HTML:
  1.  
  2.         <script type="text/ruby">
  3. class Pi
  4.         def initialize
  5.                 @a = 355.0
  6.         end
  7.        
  8.         def calc
  9.                 b = 113.0
  10.                 return @a / b
  11.         end
  12.        
  13.         PI = 'PI is about'
  14. end
  15.        
  16. puts Pi::PI
  17. puts Pi.new.calc
  18.         </script>
  19.  
  20. <body onload="prettyPrint(); new HotRuby().runFromScriptTag('/compileRuby.cgi')">
  21.  

Since you can run on any JavaScript interpreter or VM, they also support Flash.

For example, check out this Box2D example written in Ruby, running in Flash:

HotRuby Example

Posted by Dion Almaer at 8:01 am

+++--
3.5 rating from 28 votes

3 Comments »

Comments feed TrackBack URI

I hadn’t seen this… that is a definite “wow really” moment for me. …wasn’t expecting this until Screaming Monkey… thanks, Dion.

Comment by Mark Holton — March 27, 2008

Ultra cool. Kudos!

Comment by JeanHuguesRobert — March 27, 2008

Yes this is pretty cool…but also complete insanity. Why, exactly, would anyone actually want to do this?

Comment by saw — March 29, 2008

Leave a comment

You must be logged in to post a comment.