Replicant 0.2 (Ruby -> Javascript)

What it is: Replicant is a Ruby library for automatically converting
methods on Ruby classes to Javascript classes, and serializing
instances of those classes from Ruby to Javascript using #to_json.
I’ve been developing it mostly in conjunction with some Rails
projects, but it works just fine outside of Rails, too, as long as
Prototype.js is available.

Replicant is in a pre-alpha state, though I’m using it in a couple
production apps online already.

Website: No official project page yet, but a good overview of
Replicant’s current state is at http://www.codekitchen.net/articles/
2006/07/31/replicant-technical-issues

Download: No tarball yet, anonymous Subversion access at http://
svn.codekitchen.net/replicant

= Version 0.2 (2006-08-01) (pre-alpha)

== Summary

In the process of working on a few of my recent web projects (a
couple Rails, one straight Ruby/CGI) I’ve begun writing a Ruby
library for automatic translation of Ruby classes to Javascript
classes. I’ve been trying to make my AJAX-driven apps more
responsive, which basically means making fewer calls to the server,
and it was bugging me that I was repeatedly writing a Ruby class,
only to then write another class in Javascript with the same name and
sometimes even some of the same methods.

Replicant is still in a very early state, but to be honest I’m not
sure if it’s much more than a cool toy, so I want to release it to
the Ruby community and see where people find it useful, if at all.
Any feedback (what you like about it, what you don’t like, how you
might use it in your projects) will be very appreciated.

Only a limited subset of Ruby syntax is supported right now, see my
journal article linked above and the replicant.rb source comments for
details on what can’t be done. I’ve basically added support for
syntax as I’ve needed it, so it’s pretty random what works and what
doesn’t. (i.e., support for the Enumerable mixin and yield work,
but simple while-loops don’t.)

== Aknowledgement

  • I can’t take much of the credit, the real work is done in ParseTree
    and SexpProcessor. Thanks to Ryan D. and Eric H. for an awesome
    library.

On 01/08/06, Brian P. [email protected] wrote:

What it is: Replicant is a Ruby library for automatically converting
methods on Ruby classes to Javascript classes, and serializing
instances of those classes from Ruby to Javascript using #to_json.
I’ve been developing it mostly in conjunction with some Rails
projects, but it works just fine outside of Rails, too, as long as
Prototype.js is available.

Replicant is in a pre-alpha state, though I’m using it in a couple
production apps online already.

I’ve been doing a bit of work on the something similar. Did you see
this?
http://po-ru.com/diary/convert-ruby-to-javascript/
http://po-ru.com/diary/thoughts-on-ruby-to-javascript-conversion/

That was a quick hack that pointed out some obvious shortcomings (the
languages are similar, but not that similar), so I decided to take
another tack and implement something close to Ruby’s object model in
JS, so that a wider range of idiomatic Ruby code will work:
http://rb2js.rubyforge.org/

I’ll take a closer look over your code later on. Perhaps we might be
able to collaborate…?

Regards,
Paul.

Paul.

Hey Paul,

On Aug 2, 2006, at 3:08 AM, Paul B. wrote:

I’ve been doing a bit of work on the something similar. Did you see
this?
http://po-ru.com/diary/convert-ruby-to-javascript/
http://po-ru.com/diary/thoughts-on-ruby-to-javascript-conversion/

That’s cool, I wish I’d caught your original announcement to the
list. I’ve been out of the loop, working to finish up my degree for
the last month.

That was a quick hack that pointed out some obvious shortcomings (the
languages are similar, but not that similar), so I decided to take
another tack and implement something close to Ruby’s object model in
JS, so that a wider range of idiomatic Ruby code will work:
http://rb2js.rubyforge.org/

So far my development has been more about “describing” Javascript in
Ruby code, not directly supporting every part of Ruby. I make no
attempt to support Ruby-style inheritance and message dispatching,
for example. I’ve been much more concerned with making the generated
Ruby code as compatible as possible with existing Javascript code and
libraries. You seem to be aiming for a more general solution, perhaps
something that people could use without even knowing Javascript. My
code stems directly from how I’ve been utilizing it in my recent
projects, but maybe that’s why I’m having trouble conceptualizing
where I should take it next, how I can use the same code on client
and server in more cases.

I see that you’ve been focusing on builtin classes like String,
Kernel and Class so far, but are you planning to support some of the
standard library as well? I wanted to translate a method that used a
Time object the other day, and that tripped me up a bit – it was
hard to justify porting the Time class to Ruby when it’d be so much
simpler to write the code directly in Javascript.

How are you planning support for integrating with existing Javascript
code and libraries, by the way? I don’t see any mention of that.

I’ll take a closer look over your code later on. Perhaps we might be
able to collaborate…?

Yeah, I’d be totally willing. Like I mentioned, I’ve been skeptical
about how useful my approach is, so I really released this version to
gauge whether anybody else would find my approach useful, or whether
it just happened to work well in the particular projects I used it
on. I’d love to discuss it more, if you want. You can reach me at
brian <> codekitchen * net.

– Brian

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs