Getting My Feet Wet With Rubinius
Recently, Rubinius hit some major milestones. Merb runs on it; Rails runs on it. With these two Ruby frameworks running on it, I decided to get my feet wet.
I installed Rubinius using the instructions here. I had most of the prerequisites; I just had to grab libtool and bison using MacPorts.
But when I ran rake build, I encountered an error.
Unable to send initialize on #<FFI::NotFoundError> (NoMethodError)
I logged on to IRC (#rubinius on irc.freenode.net) then asked for help there.
After less than two hours, changes were pushed to the git repository, and after pulling those changes, I was able to build Rubinius. Very nice!
The first thing I did was to check if the rubinius binary actually ran. I just checked the version.
$ ./shotgun/rubinius -v
rubinius 0.8.0 (ruby 1.8.6 compatible) (3b48d1b7b) (05/20/2008) [i686-apple-darwin8.11.1]
I launched irb using Rubinius and just to check if it's really Rubinius, I sent the methods.sort message to irb and compared it with MRI's irb methods.sort. They were different. I guess it works.
I then tested out other methods in irb. One thing that I immediately noticed was the local_variables in irb duplicates things. (This happens only in irb but not in Ruby scripts running on Rubinius. MRI gets this right.)
irb(main):004:0> local_variables
=> ["_", "_"]
One of the features I really wanted to check out was bytecode compilation.
I quickly made up a simple (and useless) Ruby script, dum.rb.
module Fields
def self.included(base)
base.extend(Fields::ClassMethods)
end
module ClassMethods
def field(sym)
attr_accessor sym
puts "Added the field '#{sym}' to the class '#{self}'"
end
end
end
class TestClass
include Fields
field :name
end
t = TestClass.new
t.name = "Tim"
puts t.name
I ran this script using Rubinius.
$ ./shotgun/rubinius ~/dev/lab/rubinius/dum.rb
Added the field 'name' to the class 'TestClass'
Tim
It created another file, dum.rbc. I ran this compiled code and it worked.
$ ./shotgun/rubinius ~/dev/lab/rubinius/dum.rbc
Added the field 'name' to the class 'TestClass'
Tim
I then moved the Fields module to another file, fields.rb, and required it. Running this new script created a separate fields.rbc. I required fields.rbc instead of the fields.rb and it still works.
This means that, as the Rubinius main page says,
... you can distribute in easy-to-install packages similar to jar files. Other measures to protect intellectual property can be easily added.
That's a big plus for those who like to develop in Ruby in a closed source environment.
When I have the time, I plan to check out Rubygems in Rubinius next.




Comments
This post has no comments.