views:

276

answers:

3

I believe I have put the question quite clearly and in a concise manner. Why do I ask?

I am to explain Ruby on Rails framework to students and this requires me to make some analogies to the Java world (as the course is quite Java-centric). I have no hands-on experience with Ruby on Rails but I sense the Gem/Jar analogy is a valid one.

Could anyone perhaps shed more light on this issue?

+2  A: 

I'm not sure is that easy...

I think that a Gem is basically the same thing as a jar, but a Gem has to have a name and a version, a jar does not have this, hm, let's say..., restrictions.

The Jar mechanism was created for packaging and just for packaging. The most important, IMHO, in the Gem is the RubyGems project The RubyGems feature set is a little larger than just packaging, in involves package distribution and installation.

I think that the Apache Maven distribution and installation mechanism is the closest thing the Java community has from the Ruby Gems.

razenha
thanks for the maven analogy
Peter Perháč
+10  A: 

As a short answer I would say: Yes, it is valid.

As a long answer I would say: Yes, it is valid, but there are some important distinctions you may want to describe as well.

A jar has some qualities that makes it very different from a gem. JARs are packaged executable libraries that you generally have to explicitly declare a dependency upon in a Java program's execution at invocation time (by declaring the jar as a dependency when you invoke the java interpreter). The jar has little structure enforced upon it other than a few well defined locations for files (e.g. directory structure must mirror package path).

A Gem is a descriptor for installing a library to a system permanently as well as a package of functionality made available to be declared a dependency during runtime. A gem has a strict versioning syntax as part of its definition, and gems tend to be distributed from few centralized repositories that spend a decent amount of effort to ensure uniqueness in gem names. Gems can explicitly declare their dependencies on other gems. (Contrast with JARs where you must make sure you have all of the dependencies for a jar satisfied at invocation time and jars do not explicitly adopt the responsibility for dependency declaration OR resolution). Additionally there is some optional functionality built into the gem tool that can be quite convenient, for example you can declare a default executable for a gem to be invoked if a user wishes to "run a gem", and you can declare a unit testing suite for a gem so that a user who installs a gem can ensure its functionality.

Also you might want to describe to your students that RubyGems is a tool created independently of the Ruby language itself, and that it benefits after many of the inconveniences and complaints that arose from managing jars had been well exposed from years of Java development.

animal
+1; + since you have provided such an exhaustive answer, I'll accept this one :)
Peter Perháč
+1  A: 

As a simple explination comparing them to JARs is good enough for a basic Ruby class. For a more detailed explination see holychao's answer. The analigy that comes to mind for me is that Gem's are to Ruby what CPAN is to Perl.

Jared