9th - 15th January 2006

Ruby Weekly News is a summary of the week’s activity on the ruby-talk mailing list / the comp.lang.ruby newsgroup / Ruby forum, brought to you by Tim Sutherland and Jonathon Mah.

It’s a shortie newsletter this week.

User Group News

Quote of the Week

  • rue teaches piglet about symbols on #ruby-lang
  • James Britt:

    “When I use a symbol,” Humpty Dumpty said, in a rather scornful tone, “it means just what I choose it to mean – neither more nor less.”
    “The question is,” said Alice, “whether you can make symbols mean so many different things.”
    “The question is,” said Humpty Dumpty, “which is to be master – that’s all.”

    —With apologies to Lewis Carroll (1832-1898) Through The Looking Glass 1871

Threads

Packing (#62)

Ruby Quiz this week comes from Ilmari Heikkinen: write a program to pack boxes of different dimensions as tightly as you can.

Regexps: Perl vs. Ruby

Sam Dela Cruz inquired why the regular expression /^[\d\.]+$/ matched differently in Perl and Ruby. David A Black responded, “^ and $ match start and end of line, not string. For start and end of string, you want \A and \z (or \Z to ignore final newline).”

String#split, respecting quotes?

Richard Livsey asked how to split a string %Q{some words "some quoted text" some more words} into an array ["some", "words", "some quoted text", "some", "more", "words"]. Solutions using regexps flew in. Tim Hearney noted that the CSV module can do just that:

require 'csv'
CSV::parse_line('some words "some quoted text" some more words', ' ')

Florian Groß pointed out the Shellwords module. Both have their advantages.

Postgres-ing? Too many choices!

Dave Howell found three different gems for talking to PostgreSQL databases: postgres, postgres-pr and ruby-postgres.

What’s the difference between them?

Dave Lee said that postgres and ruby-postgres are in fact the same project – the latter is the newer name of it.

postgres-pr is a “pure Ruby” library that doesn’t need PostgreSQL’s libpq native library (but has fewer functions than ruby-postgres, which wraps the native library).