views:

186

answers:

6

In Java when you compile a .java file which defines a class, it creates a .class file. If you provide these class files to your coworkers then they cannot modify your source. You can also bundle all of these class files into a jar file to package it up more neatly and distribute it as a single library.

Does Ruby have any features like these when you want to share your functionality with your coworkers but you don't want them to be able to modify the source (unless they ask you for the actual .rb source file and tell you that they want to change it)?

+1  A: 

Ruby is

A dynamic, interpreted, open source programming language with a focus on simplicity and productivity.

So like all interpreted languages, you need to give the source code to anyone who want's to execute your program/script.

By the way searching "compiled ruby" on google returned quiet a few results.

Tahir Akhtar
A: 

I don't think there is one. Ruby is purely an interpreted language, which means ruby interprets your source code directly in order to run it. Java is compiled, so there's an intermediate bytecode (the .class). You can obfuscate your ruby if you really wish, but it's probably more trouble than it's worth.

Just to make sure you realize, however, upwards of 95% of Java can be decompiled back into source using various free utilities, so in reality, Java's compilation isn't much better than distributing Ruby source.

zenazn
If you don't trust your coworkers, how do you know they won't be decompiling and replacing your class files ? This whole question seems a little bit surrealistic to me.
Valentin Rocher
If you can't trust them to not change your files, I don't see why you trust them to not decompile the .class files.
Nathaniel Flath
+1  A: 

This is not a language specific problem and one that can be managed more effectively through source control software.

John Nolan
+6  A: 

I believe the feature you are looking for is called "trust" (and a source code control repository). Ruby isn't compiled in the same way that Java is, so no you can't do this.

tvanfosson
+4  A: 

I have to say your are in a rough position, not wanting to share code with a coworker. However, given that this is an unassailable constraint perhaps you could change the nature of the problem.

If you have a coworker that needs access to some service provided by a library of yours, perhaps you could expose it by providing a web/rest service instead of as a .rb file.

This way you can hide your code behind a web server, and if there is a network architecture that allows for low latency making these service calls, you can effectively achive the same goal.

Trust is a lot easier though.

edit: Just saw this on HN: http://blog.astrails.com/2009/5/12/ruby-http-require, allows a ruby file to include another file through http instead of the filesystem.

Nathan Feger
Interesting. Would this REST idea work even if it's not a web application?
pez_dispenser
well a REST api is delivered through a web server. However, you could simply deploy your app on an internal server that is not generally available to the whole of the internet.
Nathan Feger
+1  A: 

There is a library called ruby2c that compiles a subset of Ruby into C code (which you can then compile into native code, if you want).

It was actually originally written as a Ruby code obfuscator (but has since been used for lots of other stuff, including Ruby Arduino development).

Sarah Mei