The Strange Loop
Checking out JRuby … there were an awful lot of dynamic language presentations at The Strange Loop this past weekend.
Checking out JRuby … there were an awful lot of dynamic language presentations at The Strange Loop this past weekend.
It's early in the morning so I thought I'd write some thoughts before I continue on with my day. I've been working on abooklog as a side project to help keep track of reading for school. When deploying it I decided to go with JRuby as I really like its speed as well as its native threaded nature.
Your life of Ruby + Java is going to be fun and painful. I hope this will get you started quickly so you can move on to the more annoying stuff. (JRuby is still amazing though. JVM is also quite lovely from what I've read.)
Required: Make sure you have a Java VM and Postgresql setup.
Download JRuby 1.3.1. (Archived. Already built.):
http://kenai.com/projects/jruby/pages/Home
Extract the contents.
Go to that folder:
cd jruby-1.3.1
Check everything is ok:
bin/jruby -v
Now do:
bin/jruby -S gem install sequel
Now go to: http://jdbc.postgresql.org/download.html
Download a driver (.jar file) where it says "Current Version."
Remember the location.
Now to test if it works:
# FILE NAME: quick_start.rb
require 'rubygems'require '/Path/To/Driver/postgres-..-..jdbc4.jar' # Put the path/filename of the driver you downloaded. require 'sequel'host = 'localhost'
db_name = 'my-database' # <=== Change this.
user = 'my-username' # <=== Change this.
pass = 'my-password' # <=== Change this.
DB = Sequel.connect( "jdbc:postgresql://%s/%s?user=%s&password=%s" % [ host, db_name, user, pass] )my_table = :schema_info # <=== Change this.puts DB[ my_table ].all.inspect
Now do:
bin/jruby ~/Path/To/quick_start.rb
If it works, you can go and properly install and integrate JRuby into your system: http://kenai.com/projects/jruby/pages/Home
(Go to: "JRuby Basics" > "Getting Started")
There is also: "JRuby Basics" > "Walkthroughs and Tutorials"
COMMON MISTAKES:
Eventually, I gave up JRuby for Ruby Enterprise Edition. http://www.rubyenterpriseedition.com/
Here is the code for Mephisto to Posterous. Hmm seems all my code on this blog is about Posterous. Need to diversify.