Difference between Ruby and JRuby

Hi,

Can anyone tell me what is the difference between ruby and jruby?

I have read that JRuby means, java implementation of Ruby. What does
that mean? Is it mean that ruby interpretor is written in java?

Also, Is all ruby API methods are available in JRuby? like array, hash
etc.

Thanks,
Mike.

The essential difference is that JRuby compiles down to Java byte-code
and is executed on the Java Virtual Machine. MRI uses it’s own
interpreter.

This of course means you need Java installed on your system.

JRuby when used in 1.8.7 mode is fully api compatible with MRI ruby.
JRuby when used in 1.9.2 is pretty close to full API compatibility I
think, not totally sure.

There may be a few gems that give you trouble on JRuby but they are few
and far between.

Thanks Jeffrey for your instant reply.
This means that I can write the ruby code as it is which will be
interpreted by JVM and everything will be same.

Jeffrey J. wrote in post #1015074:

The essential difference is that JRuby compiles down to Java byte-code
and is executed on the Java Virtual Machine. MRI uses it’s own
interpreter.

This of course means you need Java installed on your system.

JRuby when used in 1.8.7 mode is fully api compatible with MRI ruby.
JRuby when used in 1.9.2 is pretty close to full API compatibility I
think, not totally sure.

There may be a few gems that give you trouble on JRuby but they are few
and far between.

In terms of what you write, there is no difference, it is all ruby. The
magic happens further down.

It is only when you start to take advantage of JRuby’s unique features
(such as linking with java libraries) that your code really stops being
portable between MRI and JRuby

If you are on a *nix system the best way to give JRuby a try is to
install the Ruby Version Manager, use that to install JRuby then run
some of your scripts / applications ( Have a look at
http://jruby.org/getting-started ).

Thanks a lot Jeffrey.

Hi,

  I have ruby on rails app with me.Now I wanna integrate my app with 

JRuby in order to get asynchronous feature.How do I approach?
Any help would be greatly appreciated,thanks in advance

On Fri, Nov 29, 2013 at 5:38 AM, Sathish R. [email protected]
wrote:

  I have ruby on rails app with me.Now I wanna integrate my app with

JRuby in order to get asynchronous feature.How do I approach?

First, don’t start by “replying” to a 2+ year old thread; start a new
topic.

Second, just run your app with JRuby. If you have specific problems,
ask about them and provide details.


Hassan S. ------------------------ [email protected]

twitter: @hassan

Sathish -

Welcome to this group.

I’m wondering if your expectations of JRuby are realistic. What exactly
do
you mean by asynchronous? Are you referring to JRuby’s superior
threading? What specifically are you trying to improve? Have you
identified a problem?

I strongly recommend the JRuby book:

  • Keith

Thanks Keith for the reply.
Let me explain my scenario.Am basically a java programmer.One
of my client had ruby on rails app(prior to 3.9 version) with him.He
approached me and asked
to convert his existing ruby on rails app to asynchronous.He himself
suggested ,do it with Play framework.
When I raise this question with Play experts,they suggested
me to go with JRuby.Since then I have set up Jruby in my machine and
made my trails.But I could not get rid of it.
Please suggest me ,how do I go with little detail
explanation.
Thank you very much.

-Sathish Reddy

Sathish -

I wish you well, but to be honest, it sounds like youll need more
assistance than what can be provided here. In addition, although you
reiterated your request for help, you didnt answer any of the questions
I raised to help us help you. In addition, you were asked to be more
specific in your questions.

  • Keith

Keith,
Thanks for taking time to look at it.I agree that I did not answer
your questions,since I was not aware much about JRuby superior
threading and other kind of stuff.

-Sathish

On Mon, Dec 2, 2013 at 12:40 AM, Sathish R. [email protected]
wrote:

explanation.
Thanks you very much.

It sounds to me like your client wanted his existing code ported to Play
(presumably using Java or Scala).

@Sathish ,

I would strongly encourage you to do two things:

Read Using JRuby http://pragprog.com/book/jruby/using-jruby . You
can
work though it quickly and the examples and material contained in it
will
give you some ideas about how you can use JRuby to improve the
performance
of your clients app. You might also want to check out Deploying
JRubyhttp://pragprog.com/book/jkdepj/deploying-with-jrubyas it has a
lot of useful information about some of the main deployment
options.
2.

Spend some time reading through articles on the JRuby
wikihttps://github.com/jruby/jruby/wikias they should provide a way
to deepen the knowledge gleaned from the book,
without requiring you to spend too much time on any of them.

This should give you a better idea about JRuby, and the how and why it
is
typically used by other developers. This video, Why JRuby
Workshttp://confreaks.com/videos/1281-rubyconf2012-why-jruby-workssummarizes
some of this reasoning as well, and might be an even better
starter point.

It might be the case that you could switch the rails app to JRuby, have
it
run with very few changes, and get an immediate performance boost simply
due to JRubys better performance. The material I recommended will
assuredly instruct you in how to do this.

As for going asynchronous, it might be possible to use the Play
framework,
via JRuby, to build an asynchronous application. I dont know of anyone
who
has done that, personally, although it has probably been tried. You
cannot
just take a rails app, suddenly slap in JRuby and Play and have it be
asynchronous however. Rails and Play are each frameworks in their own
right, and Im not even sure where one would begin to hook them together.

Usually, when people talk about asynchronous code in conjunction with
Rails, they mean running selected parts of the Rails stack in an
asynchronous way. Typically I/O heavy parts. Most often, they mean
running
it with an asynchronous server.

The two libraries most typically used to do async programming in Ruby
are
EventMachine http://rubyeventmachine.com/ and
Celluloidhttp://celluloid.io/,
specifically Celluloid I/O https://github.com/celluloid/celluloid-io.
Of
those two, Id most highly recommend Celluloid, for many reasons, but
especially because it doesnt just give you Celluloid I/O for writing
asynchronous code, but instead Celluloid provides an entire concurrency
toolkit built around the Actor model. (Play framework is also built on
top
of the Actor model abstraction, but I believe Play hides this all from
you
instead of making it available to the end user).

Probably your easiest option for adding some async sauce to a Rails app
would be to swap out the server for one written with one of those two
libraries I mentioned above. Id suggest
Reelhttps://github.com/celluloid/reel-rack.
That said, you might get better improvements just switching to JRuby
for
the native threading capability
and then using something like
Pumahttp://puma.io/which is specifically intended for use in Rack
applications like those
built with Rails, or one of the other deployment options recommended in
the
book I mentioned. TorqueBox http://torquebox.org/ would be another
great
choice.

It will depend on your clients use case, and you should definitely try
several things and do some benchmarking.

-Eric West

       Thank you so much for elaborated explanation.I will follow 

the steps suggested by you,hope would find the solution.

-Sathish