Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Author Archives: Peter Cooper

By Peter Cooper / August 4, 2006

Lucas Carlson comes up with a cute trick to make Ruby feel a little more like a prototyped language by allowing you to define methods on a class in real-time through child objects, like so:

f =
f.greet = lambda {|t| "Hello #{t}!"}
f.greet "Lucas Carlson" # => Hello Lucas Carlson!

j =
j.greet "World" # => Hello World!

Find out how. A cute trick. Read More

By Peter Cooper / August 1, 2006

HTTP Request => Rails ‘params’

GET: /users => [:action => 'index']
GET: /users.xml => [:action => 'index', :format => 'xml']
GET: /users/1 => [:action => 'show', :id => 1]
GET: /users/1;edit => [:action => 'edit', :id => 1]
GET: /users/1.xml => [:action => 'show', :id => 1, :format => 'xml']
POST: /users => [:action => 'create']
PUT: /users/1 => [:action => 'update', :id => 1]
DELETE: /users/1 => [:action => 'destroy', :id => 1]

Prolific ‘Edge Rails’ blogger Ryan Daigle has written “Simply RESTful Support – And How to Use It“, a great walkthrough of the features offered by the simply_restful plugin that’s now a core part of Edge Rails and which will provide a lot of the new functionality to be seen in Rails 1.2. Read More

By Peter Cooper / August 1, 2006

Two months ago, I wrote How to Create a Ruby Extension in C in under 5 minutes. But times have changed!

2012 update: Just tested and this all works in Ruby 1.9.3 almost six years later!

Zenspider, master of all things “Ruby + C”, picked up the gauntlet and used RubyInline (previously covered here) to hand my proverbial ass back to me on a platter. All you have to have is gem install RubyInline and.. in just 43 seconds, you too could launch an editor, paste in this code, and check it out:

#!/usr/local/bin/ruby -w

require ‘rubygems’
require ‘inline’

class Example
inline(:C) do |builder|
builder.c “int test1() {
int x = 10;
return x;


No ruby.h? Read More

By Peter Cooper / August 1, 2006

Following on from the Parsing XML with REXML using Expat post about using Expat to make REXML faster, Chris Wanstrath e-mailed me to let me know about his co-worker PJ’s post, “Parse XML with Hpricot“. Hpricot, covered previously in Fast HTML parsing in Ruby with Hpricot, is a fast HTML parser for Ruby written mostly in C by Ruby legend whytheluckystiff.

PJ says that as a subset of XML, Hpricot should work fine with raw XML, and it does:

FIELDS = %w[SKU ItemName CollectionNo Pages]

doc = Hpricot.parse(“my.xml”))
(doc/:product).each do |xml_product|
product =
for field in FIELDS
product[field] =“/#{field}”).first.children.first.raw_string

There’s less hoops to jump through than with the REXML/Expat route, and it’s still extremely fast. Read More

By Peter Cooper / July 31, 2006

I have three Rails Web hosting related domains available:

If any or all of these interest you, drop me an e-mail at rubyinside /-at-/ Read More

By Peter Cooper / July 31, 2006


Tim Burks has uploaded a new article about Cocoa OS X development using Ruby. It’s an epic tutorial. He walks through from the very first steps of opening up XCode and creating your project, through to creating an interface, and on to creating a full, usable, OS X application using Ruby. If OS X development with Ruby interests you, this is the place to start. Read More

By Peter Cooper / July 31, 2006

Expat is the recognized big daddy of XML parsing. It’s a stream-based XML parser written in C and, as a library, is used for XML parsing functions by many languages. Rubyists have tended towards REXML, however, a more flexible (though infinitely slower) parser. Sam Ruby, however, has come up with some techniques to get Ruby’s REXML working with Expat. Read More

By Peter Cooper / July 28, 2006


I’ve joined forces with Obie Fernandez on the Ruby section at InfoQ, a prime news site for the enterprise software development community. The Ruby news at InfoQ has more of an enterprise feel to it than that here at RubyInside and is focused at team leaders, development managers, enterprise developers, etc, so there’s less hacking, but more high-level Ruby stuff.

For those who are morbidly curious about such things, my ugly mug is now alongside Obie’s at the About InfoQ page (along with lots of useful info about InfoQ’s unique features, if you haven’t seen the site before). Read More

By Peter Cooper / July 27, 2006

It’s time to bring in a regular feature.. Troll Of The Month. Every month or so there appears to be a new article circulating that explains why ‘Ruby sucks’ or why you shouldn’t use Rails to develop serious applications. Most of the time, they’re unbalanced and poor explained, even if the author has some valid points.

This month’s TOTM is “The Ruby Conspiracy” by Greg Luck. His heart seems to be in the right place, but it just seems like an opportunity to bash Ruby. Read More

By Peter Cooper / July 27, 2006

After writing a basic routine to print all prime numbers between 1 and 10,000 in Ruby, Pat Eyler found it took almost 3 seconds to complete, and seeked out a way to make it faster. Enter RubyInline (covered previous at RubyInside).. With RubyInline he added a basic C function into the Ruby mix and knocked down the time required to 0.3 seconds.

The code:

require "rubygems"
require "inline"

class Primes
inline do |builder|
builder.c ‘
int prime(int num) {
int x;
for (x = 2; x < (num – 1) ; x++) {
if (num == 2) {
return 1;
if (num % x == 0) {
return x;
return 1;

p =

for num in 2..10_000 do
is_prime =
if is_prime == 1
puts "#{num} is a prime number"
puts "#{num} equals #{is_prime} * #{num/is_prime}"

Read more.. Read More

By Peter Cooper / July 26, 2006

Tomasz Węgrzanowski (aka Taw) has developed a Lisp interpreter embedded in Ruby called RLisp. It’s early days and ultra-alpha-quality, but it’s a cool project. You can find the source code here, and Taw is offering free beer for the first 10 developers to write a cool RLisp program. RLisp already has some basic OO support (and even HTTP support) so it’s fun to play with. Read More

By Peter Cooper / July 25, 2006

_why announces a release of a new UTF-8 library (which adds UTF-8 support to Ruby, without using KCODE) by Nikolai Weibull. _why has also packaged it up (unofficially) into a gem to make it even easier to install (not all of us use git). Here’s some demonstration code: Read More

require ‘encoding/character/utf-8′
str = u"hëllö"
#=> 5
#=> 5
#=> "ël"

By Peter Cooper / July 24, 2006


O’Reilly have released the long awaited Ruby Cookbook by Lucas Carlson and Leonard Richardson, a 906 page bonanza of Ruby recipes, tips and tricks. The Perl Cookbook was an essential book for Perl programmers, and it looks like the Ruby Cookbook could become similarly important in the Ruby world.

(You might want to try the trick of using the coupon code DSUG to get 30% off again – as worked with the recent O’Reilly RJS book, if it’s still valid..) Read More

By Peter Cooper / July 23, 2006

Scott Laird has announced the release of Typo 4.0, the first release of the original Rails powered blogging tool this year:

I’d like to announce the release of Typo 4.0.0, the latest version of the most widely-used Ruby-based blogging software. This is the first official release of Typo 4.0, and the product of almost a year’s work by the Typo team. This is a huge upgrade over the previous Typo release, version 2.6.0. You can download it from Rubyforge, or you can use the new Typo .gem and installer.

Typo appears to have lost some mindshare in the Rails blogging community to Rick Olson’s Mephisto (the official Rails blog migrated to Mephisto just a month ago), but Typo has made a whole lot of changes and improvements (podcast support, file uploads, Jabber notification, better caching and themes support, redirection system for people migrating from other blogging tools, etc). Read More