Learning Ruby 1.9 7

Posted by mikong on December 25, 2007

I’m not going to list down “improve Ruby skills” on my New Year’s resolution. With the newly released Ruby 1.9.0 (a development release) and beta book Programming Ruby 3 by Dave Thomas (or simply Pickaxe 3), what better time to dig deeper into Ruby than now?

When I setup Rails on my mac a few months back (before Leopard and Rails 2.0), I followed Building Ruby, Rails, Subversion, Mongrel, and MySQL on Mac OS X by Hivelogic. Following the Ruby part of that but updated for Ruby 1.9:

  cd /usr/local
  sudo curl -O  ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.0-0.tar.gz
  sudo tar xzvf ruby-1.9.0-0.tar.gz
  cd ruby-1.9.0-0
  sudo ./configure --prefix=/usr/local/ruby-1.9.0 --enable-pthread --with-readline-dir=/usr/local
  sudo make
  sudo make install

I didn’t have to run ‘make install-doc’ because ‘make install’ already installed the documentation. Since I haven’t upgraded to Leopard yet, this has only been verified on Tiger. Running ‘/usr/local/ruby-1.9.0/bin/ruby -v’, I got

  ruby 1.9.0 (2007-12-25 revision 14709) [i686-darwin8.11.1]

Cool! And I just bought Pickaxe 3 (right after installing). Looking for the first 1.9 feature I can find in the book… a new hash syntax:

  $ /usr/local/ruby-1.9.0/bin/irb
  irb(main):001:0> inst_section = { cello: 'string', clarinet: 'woodwind' }
  => {:cello=>"string", :clarinet=>"woodwind"}
  irb(main):002:0> inst_section[:clarinet]
  => "woodwind"

It works! And let me just add that new hash syntax looks gorgeous. Now I have to end this article and try a 1.9 feature beyond mere syntax updates. Chapter 11: Fibers, Threads, and Processes looks like a good place to start… :)

Update 12/26/2007: I initially installed Ruby 1.9 on /usr/local. It installed rubygems 1.0.1 with it and messed up my gem installation for 1.8.6. I had to reinstall 1.8.6, and then reinstall ruby 1.9 in an isolated directory, /usr/local/ruby-1.9.0. I updated the article to use this directory. For now, I only use 1.9 to try the new features. If you need to work with multiple versions of Ruby, you might want to check out Dan Manges’ article.

Trackbacks

Use this link to trackback from your own site.

Comments

Comments are closed.

  1. topher Wed, 26 Dec 2007 12:41:03 UTC

    Does Rails 2.0 run on Ruby 1.9? What is the main improvement in 1.9? Is it performance?

  2. mikong Wed, 26 Dec 2007 14:10:47 UTC

    There are recent updates in edge Rails to make the framework compatible to Ruby 1.9, so it looks like they are working on it. But note that Ruby 1.9 is a development release, so we can’t expect it to be stable. Also, we need to wait for web servers like Mongrel to support Ruby 1.9.

  3. mikong Wed, 26 Dec 2007 14:32:18 UTC

    As for improvements in 1.9, I think YARV (the new Ruby interpreter) is the most talked about. It’s expected to deliver a big performance boost. Another feature is for multi-threading, fibers.

    There are also a lot of small changes, like the new hash syntax and some of the deprecated methods in 1.8 were completely removed, like Object#type.

  4. Geoff Wed, 26 Dec 2007 22:29:38 UTC

    Seems to work fine on Leopard. Thanks for the instructions.

  5. Alex Egg Wed, 26 Dec 2007 22:42:02 UTC

    Don’t forget about Fixnum:odd? !!

  6. roger Fri, 21 Mar 2008 18:22:54 UTC

    Wow that is indeed gorgeous. I would imagine that mongrel and such work fine on 1.9 (at least eventmachine does…but not sure).

  7. Lyle Thu, 31 Jul 2014 13:04:16 UTC

    < a href = “http://google.com/?p=30&lol= eileen@diplomatic.neuralgia”>.< / a >…

    tnx….