views:

444

answers:

5

You can compile a Java application and run it in any machine where the Java virtual machine is located, independently of the underlying hardware.

Since Ruby on Rails was built upon Ruby, I'm concerned if building software in Ruby in any environment is the same or not. There exists versions of Ruby for Windows, Linux and Mac at least.

So, could you do the same with a Ruby application and with a Java application? In other words, how cross-platform is Ruby?

EDIT: I mean Ruby by itself, not Ruby running in another virtual machine like in jRuby. Should I expect more cross-platform gotchas development in Ruby than in Java or are both almost the same?

+7  A: 

Ruby is a scripting language and it is interpreted at the run time by the Ruby interpreter , The Ruby code is interpreted and converted to machine level language i.e Assembly code . Talking about the platform Independence you can run ruby code in any of the the platform like Linux ,Windows or Mac if you have platform dependent Ruby Interpreter installed.

Where as in Java , it is Compiled and converted to an intermediate byte class and this byte class is interpreted by platform dependent JVM (Java Virtual Machine ) .

In that way you can think you Ruby source file as byte class which can be run on any platform ,with one difference byte class is already compiled but ruby source file will be compiled at the Run time .

YetAnotherCoder
Why was this down voted twice? The question is vague at best and a flamewar starter at worst. This answer is a good one. (I rescued you a little with a +1.)
jdl
Interpreted languages (like Ruby) generally function the same on a multitude of different platforms. All of the platform-specific heavy lifting is done when the interpreter is ported, and the scripts can expect to function the same on any platform where an interpreter is available. The big caveat is libraries. Some libraries may not be available for all the same platforms that Ruby is. Therefore, if you use a (for example) Linux-only library and try to run your code on a Windows box, your code will not be truly "cross-platform" (although this is no fault of the language itself).
bta
A: 

Java is only cross platform if the developer puts in the time and effort to avoid messing up "/" and "\" in directory paths and not assuming character sets or screen resolutions. You'd be amazed at how may times this becomes an issue in an environment where the developers work on windows but deploy to unix.

Rails runs on java. You can use JRuby and warbler to build a java war file that can be deployed like a native java app. There is going to be some munging to get gems installed and the like, but it works pretty well.

So if you use JRuby and pay attention to the common porting issues, Ruby is at least as portable as Java.

sal
Java code runs on embedded platforms, which tend to use lightweight, specialized VMs that use a Java bytecode version that predates JRuby (and Jython, Clojure, Scala, etc.). The result is that Java runs on embedded platforms, but most (possibly all) other languages targeting the JVM don't work on embedded platforms. That's not to say that Ruby is less portable; it just means that porting to the JVM doesn't make a language just as portable as Java.
Imagist
I'm pretty sure Java will transparently handle / vs \. And I wouldn't really call screen resolution and encodings a cross-platform issue, since they don't depend on CPU architecture or OS.
Michael Borgwardt
@michael, this was meant as an example of the type of issues that come up in portability. Its usually environmental issues and not language or tool chain issues.
sal
Java transparently handles \\ vs / in java.util.File. I'd be amazed if this was ever an issue. new File("C:/input.txt"); would work just as well as new File("C:\\input.txt");, assuming that the filesystem understood C:.
Dean J
+1  A: 

If nothing else, you could run JRuby, a Ruby interpreter written in Java.

Joe Caffeine
JRuby won't run on many embedded systems which use an older, incompatible version of Java bytecode.
Imagist
+3  A: 

Ruby binds fairly closely to the underlying platform. This is especially the case when it comes to process/threading mechanisms, and various forms of IPC. These are more significant challenges to overcome, compared to "trivial" ones as directory seperator, and so forth. I'm pretty sure that there isn't parity between, say, the Windows Ruby runtime and the Linux Ruby runtime.

With Java, the IPC/process/thread model is the same on all platforms that runs the JVM.

Svend
A: 

As long as you don't touch hardware or threading, Ruby should work on the three major operating systems. For web development, Ruby will mostly work the same everywhere. For more advanced applications, no.

Dean J