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:

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

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

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

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.4 rating from 29 votes


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.