March 2007 Archives

Gregory Brown

AddThis Social Bookmark Button

We’ve put some effort into increasing the signal on this blog over the last week or so.

I personally am super happy with the new content up here. But it’d be interesting to see what folks think about our progress as a whole.

So like a truck driver with a “How’s My Driving” sign on his big rig, I’ve created a Jyte claim.

It’s simply, “The O’Reilly Ruby Blog has improved since 2007.03.21″

Anyone with an OpenID can come support or bury this claim, and let us know if we’re truckin’ fine or veering off the mountain.

I’ll try to stop with the meta-posting… expect a Digging Deep article soon!

Curt Hibbs

AddThis Social Bookmark Button

I am often asked if I think that clones of Ruby on Rails will become available in insert-your-language-here, and my answer is always “yes and no”.

One of the biggest contributions that Rails has made to the industry as a whole was that it challenged the conventional wisdom about the way things should be done. In doing so, it showed that there was a better way by actual demonstration. Many of ideas behind Rails are, in fact, being cloned in other languages and their web frameworks. But it is my firm belief that, while these clone/borrowers can approach the productivity of Rails in their language, they will not be able to match Rails completely. The reason for this is found in one simple word: Ruby.

The Ruby programming language has a unique confluence of features that made Rails possible. Those of us who have been programming in Ruby for a long time intuitively understand what those language features are, and how they synergistically combine to form the programming language that makes Rails possible. We can even tick this feature list off in our sleep. But it is rare that we are able to articulate the gestalt of these features in a way the nubies can truly understand and appreciate. I know that I haven’t been able to do it!

Fortunately, the pressure is off because Jacob Harris knows how to do it, and he wrote a short PDF book that does precisely this: Rubyisms in Rails (available from Addison-Wesley for $9.99). This book just made my A-list of books I recommend to people who want to know what makes Ruby so special.

From the book’s web page:


Rubyisms is an examination of how the style of Ruby informs the design of Rails. In particular, it looks at a few specific examples of how Rails’ internal code is implemented in Ruby to instruct about Ruby’s design principles. The main goal is simply aesthetic appreciation. But, if you are a beginning programmer in Rails who is stymied in your understanding of Ruby-or an intermediate Rails developer still writing code that looks like Ruby-tinged PHP or Java-this Short Cut will hopefully impart enlightenment and inspiration about the Ruby way of programming. It also reveals how the revolutionary design of the Rails framework can only be built upon the beauty of Ruby.

The book is also available on O’Reilly’s Safari Online service: http://safari.oreilly.com/0321474074/pref01

Very highly recommended!

AddThis Social Bookmark Button

Over the last couple of Ruby releases I’ve made some improvements (with Eric Hodel’s help and blessing) to RDoc for C extensions that I thought I would share with you. If you write C extensions with Ruby then keep reading. If you don’t do C and/or don’t care that much about RDoc, this post may not be that interesting for you. :)

Jim Alateras

AddThis Social Bookmark Button

Here is a nice looking javascript date widget that you can embed in your RoR application. Instructions on installing the widget into your Rails applications is provided on the home page.

I’ll definitely be giving it a whirl.

Ryan Leavengood

AddThis Social Bookmark Button

I haven’t posted here in a very long time, but I recently got a full-time job using Ruby and Rails (hurray) so Ruby is more on my mind lately. In fact I’ve gotten a better understanding of what life is like for the average Rails developer by seeing how my co-worker Alex writes his Ruby code. Now Alex is a smart guy, he has been doing web-sites for years, is proficient in ColdFusion, PHP , Flash, HTML and CSS, yet his Ruby code is not always as elegant as he or I would like. Of course I’ve been using Ruby for almost 6 years so know it quite well (and that is a big reason why I was hired.)

Still even I find the occasional new nugget and figured this blog would be a good forum to expose some of my new insights. This way other Rails developers like Alex who aren’t as proficient in Ruby as they would like can benefit from my experience.

Recently I was perusing the documentation for the Enumerable module and took a closer look at the grep method. This method is surprisingly more powerful than it might seem at first glance. To learn more, please continue reading this entry…

Gregory Brown

AddThis Social Bookmark Button

This came up in #camping today and I figured it was worth at least a mention:

Vanilla HashWithIndifferentAccess is slightly more choosy than Camping’s.

A quick irb session with each shows the difference.

From active_support

>> require "active_support"
=> true
>> a = HashWithIndifferentAccess.new
=> {}
>> a.apple
NoMethodError: undefined method `apple' for {}:HashWithIndifferentAccess
        from (irb):4
>> a.apple "bar"
NoMethodError: undefined method `apple' for {}:HashWithIndifferentAccess
        from (irb):5
>> a.apple = "bar"
NoMethodError: undefined method `apple=' for {}:HashWithIndifferentAccess
        from (irb):6

From camping

>> require "camping"
=> true
>> a = HashWithIndifferentAccess.new
=> {}
>> a.apple
=> nil
>> a.apple "bar"
NoMethodError: apple
        from /usr/local/lib/ruby/gems/1.8/gems/camping-1.5/lib/camping.rb:51:in `method_missing'
        from (irb):5
>> a.apple = "bar"
=> "bar"

This is not a complaint, just an observation I hope will be helpful. :)

Jim Alateras

AddThis Social Bookmark Button

Since picking up RoR I have had to dig in to technologies which I had previously only glanced at. One of these is CSS, part of the DHTML set of technologies.

The experience has been rewarding and at times frustrating but the outcomes has been positive. It is a technology that people need to get their heads around in order to develop an effective and usable front end to your web application.

Here are some resources that eased the learning curve

Books

Debugging Tools

Editors

Gregory Brown

AddThis Social Bookmark Button

The following may be a bit of an ‘Advanced NubyGem’ but I think this is an interesting idiom that most people will have to work with.

Sometimes in Ruby you’ll see things, both in core and third party libraries, that look a bit like class names that take arguments.

You may of already seen these in the form of Integer(), Array(), etc.

>> Integer(1)
=> 1
>> Integer("1")
=> 1
>> Integer("")
ArgumentError: invalid value for Integer: ""
        from (irb):3:in `Integer'
        from (irb):3

These weird looking methods are just alternate constructors. They can really come in handy as a way to simplify the most common ways of building a given object, or giving them some different behaviors.

Here is an example from Ruport:

The long way of constructing a Table object:

  table = Ruport::Data::Table.new :data => [[1,2,3],[4,5,6]],
                 :column_names => %w[a b c]

This is the shortcut interface:

 table = Table(%w[a b c]) << [1,2,3] << [4,5,6]

This is usually less typing and looks a little cleaner. Of course, it doesn't support the same exact options of the original constructor, but that's what we're going for afterall.

How it's done

Implementing these methods is as simple as using capitalized method names. In Ruport, we are currently a little surly and do this right on Kernel so you can get the constructors everywhere:

module Kernel
   def Table(*args)
        #implementation here
   end
end

A safer way

Instead of sticking these methods in Kernel, you can play it safe and put them in a module,
this way, they only are available where you include them. For example, if enough people complain, we’ll probably do something like this:

module Ruport::Data::Shortcuts
   def Table(*args)
       #....
   end
end

This way, people would be able to use these shortcuts just in certain classes by including the module in them. If you’re worried about your names conflicting with others, this might be a good idea.

Don’t Overuse Your Shortcuts!

I should fix this problem before I tell folks not to do it, but right now bits of Ruport code use the shortcut methods internally. Unless you have a really compelling reason (other than laziness) to do this, Don’t!

The very thing that makes it ’safe enough’ to stick these shortcuts in core is that a conflict should only break the shortcut. If you use your shortcuts internally in your code, there is a chance of some serious issues if things collide.

pat eyler

AddThis Social Bookmark Button

RubyCentral is once again a Mentoring Organization for the Google Summer of Code. While we have a very strong pool of mentoring candidates, we’d love to see more student/project applications.

Applying as a student is pretty easy, all you need to do is go here and follow the directions. If you’ve already got an idea in the Ruby, RoR, JRuby, Xruby, rubinius, etc. space please submit it. If you’re stuck, take a look at some suggested ideas here.

Do move quickly though. The window for applications closes March 24th.

Gregory Brown

AddThis Social Bookmark Button

This blog has some of the best Ruby talent floating around on it.
Problem is, it seems like many folks are too busy, too tied up with other blogs, or too (something) to post here.

Some of us want to turn that around. I’ve been talking community for the last week or so, and I’d like to start eating my own dog food right here at home.

We’ve already started discussions on the internal mailing list, I’m willing to open Pandora’s box and ask you readers what you are looking for. What things do you like and want to see more of? What things do you dislike and want to see banned from ORA and possible chased by an army of undead pirates?

If you go back and look at the list of authors we have here, there is serious potential for a cool ruby resource. Problem is, no one knows quite what to do anymore, since the overall feel over here is a little fragile.

I was pretty excited when O’Reilly set up a Ruby blog. I’d like to see that excitement restored among the bloggers here. So, readers, what can we do to make you happy?

If it involves Chunky Bacon, so be it!

Jim Alateras

AddThis Social Bookmark Button

Today I came across this article, which describes how to install RoR on a Sun Java System Web Server 7.0.

Jim Alateras

AddThis Social Bookmark Button

Rails for All is a RoR web site, which is interested in promoting RoR as the platform of choice for user centric, database-backed web application. The site allows you to promote your Ruby or RoR users group and also register yourself or your company as RoR developers.

RoR content portals are springing up all over the place.

Gregory Brown

AddThis Social Bookmark Button

The second day of MWRC has passed, and I’m sad to see the conference end. It was really a great time, preserving the feel of RubyConf while having a local flare to it.

Again, I took spotty, horrible notes, so I apologize for the entirely reactionary post, but I do want to provide a comprehensive report of the conference.

Saturday was largely a day of low level bits, featuring talks from John Lam on RubyCLR, Charles Oliver Nutter and Thomas Enebo on JRuby, and Michael Hewner on Ruby USB. Unfortunately, Kirk Haines was ill and didn’t get to talk on IOWA, but the replacement code review by Marcel Molina and Jamis Buck was actually pretty neat.

Jim Alateras

AddThis Social Bookmark Button

There has been more talk on top RoR blogs on the the ror-talk mailing list this week. Here are five blogs i subscribe too.

Jim Alateras

AddThis Social Bookmark Button

It’s old news now that Aptana has picked up the RadRails development effort and you’d probably notices that the radrails.org domain no longer exists. The new domain is radrails.net. Aptana has already introduced nightly builds and are working towards a 0.8 release, although I couldn’t find any information on time lines.

This is all good news for Eclipse users like myself. Currently, I am getting by with the 0.7.2 and the command line but ‘chafing at the bit’ for Aptana’s first release.

Gregory Brown

AddThis Social Bookmark Button

I am out at MountainWest RubyConf and so far, it’s been a great time. I didn’t take detailed notes, but I’d like to share a few highlights from the first day here. The talks have been great, the conversations even better, and we even have wifi + power!

James Britt

AddThis Social Bookmark Button

Reports of the death of Ruby Code & Style have been greatly exaggerated.

I’ve been the Editor-in-Chief of Artima’s Ruby Code & Style for somewhat over a year now. For various reasons, I am stepping down.

Just to be clear, I’ve had nothing but good experiences helping get the ‘zine up and out the door, and have endless appreciation for all those who pitched in and made things happen. It’s mainly a matter of time; I cannot give it the attention it deserves.

I expect a formal announcement on this to appear on the RC&S site before long, so I’ll the details to that. But I want to at least assure people that that the ‘zine has not simply up and died. It continues.

So there is at least one Ruby magazine (albeit online-only) that is around. But people should appreciate that organizing and maintaining a good publication is non-trivial.

Getting and preparing a steady flow of high-quality material is not easy. It’s a job. The goal for RC&S was to publish content a cut above what one typically finds in, say, Linux Journal or on most blogs.

That’s not meant as knock on those sources, just that there is zero reason to publish one more “How To Write a Blog in Rails” article.

Jim Alateras

AddThis Social Bookmark Button

Recently on the ror-talk mailing list there was a question on navigational menus, which revealed some interesting resources.

link_to_unless_current helper
Goldberg, Integrated Site Design for RoR
NavTab Plugin”

The navtab plugin, which is part of SeeSaw toolbox, is a neat little plugin, which provides instant support for tabs in your web applications. We will definitely be using this on our next RoR application.

Gregory Brown

AddThis Social Bookmark Button

I’ve been running local special need gem servers as well as a gem server for beta versions of Ruport and support code (namely plugins). I got tired of manually wget’ing the gems I needed and their dependencies, so with a little help from mechanize and archive_tar_external, my friend Dinko and I came up with this quick (pretty messy) hack.

require 'rubygems'
require 'archive/tar_external'
require 'mechanize'
require 'fileutils'
include FileUtils
include Archive

module RFDownloader

  def populate(archive)
    mkdir ".rf_downloader"
    cd ".rf_downloader"

    yield

    Tar::External.new( "../#{archive}.tar",
                       "*.gem", "gzip")
    cd ".."
  end

  def get(pattern,options={})
    link = "http://rubyforge.org/projects/#{options[:project]}"
    agent = WWW::Mechanize.new
    page = agent.get(link)
    page.links.find { |l| l.text[/File/] }.click
    link = agent.page.links.find { |l| l.text[pattern] }
    link.click.save_as(link.text)
  end

  def fetch(opts,&block)
    populate(opts[:archive]) do
      module_eval &block
    end
  end

  module_function :fetch, :populate, :get

end

With this, we were able to grab automatically a tarball filled with all the gems needed to run Ruport 0.9.0 with a tiny little script:

require "lib/rf_downloader"

RFDownloader.fetch(:archive => "ruport_deps") do
  get /fastercsv.*gem/,          :project => "fastercsv"
  get /pdf-writer.*gem/,         :project => "ruby-pdf"
  get /color-tools.*gem/,        :project => "ruby-pdf"
  get /transaction-simple.*gem/, :project => "trans-simple"
  get /RedCloth.*gem/,           :project => "redcloth"
  get /hoe.*gem/,                :project => "seattlerb"
  get /rubyforge.*gem/,          :project => "codeforpeople"
  get /mailfactory.*gem/,        :project => "mailfactory"
  get /mime-types.*gem/,         :project => "mime-types"
  get /scruffy.*gem/,            :project => "scruffy"
  get /build.*gem/,              :project => "builder"
  get /gem_plugin.*gem/,         :project => "mongrel"
end

Elegant? Nope! A way to be lazy and quickly snapshot the newest versions of a number of gems, you bet ya. Maybe someone will see this and build a nice little library that does this ‘the right way’ :)

UPDATE: Thanks to Aaron Patterson for helping me get rid of the wget call

Jim Alateras

AddThis Social Bookmark Button

I recently replied to an email on the ror-talk mailing list about resources on agile methodology and RoR. Here are four non-RoR specific resources that i have used during the past 12 months

I’d like to hear what resources other people are using?

Jim Alateras

AddThis Social Bookmark Button

It looks like development for the RadRails plugin for Eclipse has stalled and the key contributors are flat out working on a startup venture. Who can blame them we all need to eat. So the search for an alternative Windows Ruby\RailsIDE has started. I’ve read a log about textmate/, the mac os editor and was curious why they never offered a Linux/Windows version. Well the power of textmate has come to windows with .e-texteditor.

I just downloaded it the demo version and first impressions are very positive indeed. Not enough there yet to move me from Eclipse but it is getting there.

You should take a look at it.

Curt Hibbs

AddThis Social Bookmark Button

Back in 2001 when I first got started with Ruby, there were no IDEs for Ruby, so I decided that writing one would be a good way to learn Ruby. A few months later I joined forces with Rich Kilmer and we developed FreeRIDE–the only Ruby IDE that is written in Ruby. But these days its a much different story as there is a veritable plethora of Ruby IDEs available as vendors almost fall over themselves to provide Ruby support.

Someone (if anyone knows who it is that wrote this blog entry, please post a comment) has published a very nice comparative review of three of the most popular IDE choices: IntelliJ IDEA, Sun’s NetBeans, and the Eclipse based RadRails/RDT. Here is his main feature comparison chart, go read the whole review for his qualitative assessment of these three IDEs.