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

Author Archives: Peter Cooper

By Peter Cooper / August 31, 2006

def foo
‘bar’
end

module M
def foo
‘baz’
end
end

puts "should be ‘bar’: #{foo}"

self.dup.instance_eval do
extend(M)
puts "should be ‘baz’: #{foo}"
end

puts "should be ‘bar’: #{foo}"

Garry Dolley worked out some interesting Ruby-fu to create a temporary execution context on the fly using self.dup.instance_eval. Any other tricks we could use this for? Read More

By Peter Cooper / August 30, 2006

Kevin Clark presents “Things You Shouldn’t Be Doing in Rails“. It’s not a list of things Rails isn’t any good for, rather it’s features or concepts related to Rails that you shouldn’t be using. It covers deprecated finders, the in-built pagination classes, scaffolding, engines, layouts, and namespaced controllers. Read More

By Peter Cooper / August 29, 2006

Giftcertificates

The Money Train is a great book being written by Benjamin Curtis about building e-commerce sites using Ruby on Rails. It’s released as a ‘beta book’ meaning you can buy and read it in PDF form straight away, but over time you’ll get tons of free updates and eventually the full, completed book (in PDF format). Even better, it’s only $12!

It has some pretty cool ‘e-commerce recipes’ in it, so it’s worth getting for those. It covers the basic such as products, variants of products, related products, and customer reviews.. through to gift certificates, shipping, carts, payment processing, and affiliate referrals. Read More

By Peter Cooper / August 29, 2006

FileList["**/*.rb"].egrep(Regexp.new(ARGV.first))

Jim Weirich has an interesting blog post about using Rake’s ‘FileList’ class to find files on your hard drive. I’ve already started to use the example he gives here.. good find! Read More

By Peter Cooper / August 29, 2006

This isn’t particularly new, alas, but still interesting:

Got 15,842 records that you’d like to export to a file? Using the standard the Rails ActiveRecord::Base#find method will load all 15,842 into memory all at once and return them all in an array. If your app is running on a shared host, or if you’re keeping your app on a memory budget, this is a big problem for you. So you could load each record one by one, but that’ll kill your db server. Wouldn’t it be sweet if #find could return an enumerable that would load your records in batches of say 1,500 records? Read More

By Peter Cooper / August 29, 2006

Prolific PuneRuby blogger Satish Talim has just begun a course of free Ruby lessons. They’re open to anyone who wants to get involved, and so far 43 people are signed up! The lessons have already begun, but you can still get in on the action. The syllabus is available to check out, and to register to receive the lessons you only have to e-mail Satish at satish.talim /at\ gmail.com. This might be an ideal chance to get those friends who keep asking you questions about Ruby off your back ;-)

(E-mail address fixed. Sorry!) Read More

By Peter Cooper / August 27, 2006

#!/usr/bin/ruby
require ‘rubyhp’
__END__
<html>
<body>
<% cgi.params.each do |key, value| %>
<%= key %>: <%= value %><br />
<% end %>
<% if cgi.params.empty? %>
Sorry, please enter some cgi parameters. How about "?foo=baz"?
<% end %>
</body>
</html>

Christopher Cyll has put together a great little example of how to quickly create templated Web pages with Ruby without requiring any frameworks. It relies on CGI, but sometimes that’s all you need, and it makes throwing together tiny Ruby-powered Web pages possible as easy as creating a simple PHP page. Read More

By Peter Cooper / August 25, 2006

It’s not mentioned on the official Ruby homepage yet, but Matz has just announced the release of Ruby 1.8.5 on the Ruby mailing list. He claims there are no big changes from 1.8.4 and cites stability as the main benefit of upgrading. Unless you’re having problems with 1.8.4, however, I’d wait a few weeks to see how it pans out, but if you’re itching to try it out get it from http://ftp.ruby-lang.org/pub/ruby/ruby-1.8.5.tar.gz Read More

By Peter Cooper / August 24, 2006

Today I read JesusPhreak’s “Of snakes and rubies; Or why I chose Python over Ruby” and it highlighted a few of the feelings that have been running around in my head lately regarding Ruby. He points out Python’s wealth and depth of libraries, style guides, and how Python is wider used and less dependent on a single technology to promote it. While Rails is good, he seems to feel that Rails is defining the entire Ruby experience too much. I’m inclined to, sadly, agree.

While Ruby has a large life outside of Rails, Rails tends to define the experience for a great deal of new users. Read More

By Peter Cooper / August 24, 2006

Testingcheatsheet

Geoffrey Grosenbach is unstoppable! He’s put together a simple, but effective, cheatsheet for Ruby and Rails testing that’s full of assertion references. Enjoy.

Link now fixed. Thanks Mike! Read More

By Peter Cooper / August 24, 2006

The entries and the numbers associated with them were shown in the last post, so choosing a winner is as simple as using ‘rand’. For the first prize $100 drawing:

irb(main):001:0> rand(24) + 1
=> 19

1st prize of $100 goes to Duncan Beevers with Using Simile Timeline with Ruby on Rails Views. A well deserved win too, as it’s a particularly cool demonstration of how to use a JavaScript / AJAX library to show timelines on your Web pages.

And for the second drawing:

irb(main):002:0> rand(6) + 1
=> 3

2nd prize of $15 goes to Tim Shadel.

Thanks for all of the entries folks, and I hope those of you who didn’t win will still enjoy checking out the 24 great articles and resources created for the contest. Read More

By Peter Cooper / August 24, 2006

These are all the valid entries into the first prize contest from which one random winner will be chosen:

1. Setting Up a Rails Development Environment and Deploying to Textdrive by Jordan McKible.
2. Anatomy of an Attack Against Rails 1.1.4 by Evan Weaver.
3. Top 13 Ruby on Rails Presentations from TechKnow Zenze.
4. Noobies First Impression of His First RoR Project by Shane Thomas.
5. Ruby/Tk Client for SOAP Server by Satish Talim.
6. Ruby-Prof and Call Graphs by Pat Eyler.
7. Profile and Ruby-Prof: Getting Specific by Pat Eyler.
8. Security Threat Last Week by Nick Seiger.
9. Read More

By Peter Cooper / August 23, 2006

Rubyphone

RubyPhone is the first Ruby project I’ve seen relating to telephony (although if you can leave links to others in the comments, please do!) but this code example struck me as particularly interesting:

phone.answer(call) if phone.ringing?

They say it’s ultra-alpha quality, but if you’re getting into this area, it’s worth a look. Read More

By Peter Cooper / August 22, 2006

Alex Bradbury has developed Ariel, a library that uses predefined examples to work out how to extract information from other documents. It was a Google Summer of Code project and was mentioned by Austin Ziegler. More directly from Alex:

Ariel is a library that allows you to extract information from semi-structured documents (such as websites). It is different to existing tools because rather than expecting the developer to write rules to extract the desired information, Ariel will use a small number of labeled examples to generate and learn effective extraction rules. It is developed by Alex Bradbury and released under the MIT license. Read More

By Peter Cooper / August 22, 2006

Scott Laird looks at how to profile memory leaks in Rails:

One of my long-running problems with Rails (and Ruby in general) is that it’s difficult to debug memory leaks. I’ve had a number of cases where I’ve stuck something into a long-lived array or hash and discovered much later that my Ruby process was eating over 100 MB of RAM. While ps makes it easy to see when Ruby’s using lots of RAM, actually figuring out where it went is a lot harder. Read More