22

I'm working on a piece of logic that I would like to express on the server as well as in the browser. Something like validating a form where there must be certain logical relationships between the elements based on what has already been entered.

So... If I can write the logic once and somehow end up with both Ruby and with Javascript, I can write the logic just once and not have to worry about making sure that two pieces of code written in different languages have the same functional behaviour.

I don't need to reproduce everything in Ruby, obviously, and one simplification might be to port a single general-purpose library like Functional Javascript to Ruby.

Does anyone have experience with RubyJS? Can anyone point me to an existing project using RubyJS? Thanks in advance...

iconoclast
  • 21,213
  • 15
  • 102
  • 138
raganwald
  • 2,695
  • 1
  • 16
  • 8

4 Answers4

18

As far as I can tell, Opal is the best Ruby to JS converter/compiler out there right now. Here you can see it in action.

It isn't perfect, but it works most of the time and unlike older projects such as RubyJS, Opal is still being actively developed.

Private_GER
  • 185
  • 2
  • 12
Ajedi32
  • 45,670
  • 22
  • 127
  • 172
6

maybe this helps: http://opalrb.org/ haven't tried it though

Kokizzu
  • 24,974
  • 37
  • 137
  • 233
6

I know about http://hotruby.yukoba.jp/ but have never used it

Matthew FL
  • 1,612
  • 3
  • 18
  • 22
1

I recently heard about a project named "Johnson" which embeds the Spidermonkey JavaScript interpreter inside Ruby. http://github.com/jbarnette/johnson

You could then eval some javascript inside ruby.

glenn jackman
  • 238,783
  • 38
  • 220
  • 352