From: David Masover Date: 2009-03-04T20:47:07+09:00 Subject: Re: Compiling a Ruby app Rick DeNatale wrote: > On Tue, Mar 3, 2009 at 5:09 AM, David Masover wrote: > > >> Sharagoz -- wrote: >> >> >>> My second concern is protecting source code. >>> I realize that everything that can be compiled can also be decompiled, >>> >>> >>> >> That is not entirely true. Or rather, it can be "decompiled", all right, >> but not into anything resembling the original source code. >> > > > Actually closer than you might think: > > require 'rubygems' > require 'ruby2ruby' > I was speaking of compiled languages in general. As a trivial example, a common C optimization is to inline functions which are below a certain size. Now, when decompiling, how do I know what was inlined, and what really should be duplicate code? Oh, and not all compiled versions preserve debugging symbols, meaning any code that isn't actually part of an external API is likely completely without comments, variable names, method names, etc... Now, Ruby tends to be much more dynamic, meaning less of the code can be discarded by the compiler. But that doesn't mean it will look like you expect. For example: class Foo %w(one two three four five).each_with_index do |name, index| define_method(name) { index + 1 } end end puts Ruby2Ruby.translate Foo produces: class Foo < Object def five (index + 1) end def four (index + 1) end def one (index + 1) end def three (index + 1) end def two (index + 1) end end Completely out of order, I have no idea what "index" means in that context, and it only bears a vague resemblance to the source code used.