Back in March 2008, Vidar Hokstad - a London based Norwegian developer - began to write a series of blog posts on writing a compiler in Ruby from the ground up. Early on, I took objection to some elements of his approach, but it still stands as a great series of posts. Vidar recently reached post 11, providing enough of a landmark to introduce the series as a whole (which is already scheduled to go up to at least 20 posts).
It's worth noting that there are many different approaches to writing compilers of all types - so don't take the series as a definitive way to develop a compiler. Vidar focuses on outputting x86 assembly language and his example compiler (so far) has very tightly bound AST-walking to code generation stages (with no optimization or intermediate stages).
I'd be particularly intrigued to see similar content from the Ruby community - especially on targeting virtual machines (such as YARV or the Rubinius VM) or on using the Treetop library. For those interested in developing compilers generally, StackOverflow provides a lot of great resources.
Github is a great resource for finding new projects within the Ruby community. It has become an extremely popular place for Ruby and Rails developers to congregate lately, so I wanted to list some of the new projects, and some of the updated ones, that I have found interesting and that are too small for their own blog post. Let us know if you like this as we might turn it into a regular series on Ruby Inside!
This month's picks:
Disclaimer: I have no financial connection to the Pragmatic Programmers and other than through receiving these videos to review get no direct benefit from this review.
It was only a few weeks ago I announced that the Pragmatic Programmers were getting into the screencasting business. The first Ruby related videos were from the Everyday Active Record series by Ryan Bates. The reaction to these across the Ruby blogosphere has been very positive, and true to their word, the Pragmatics have been quick to release some more interesting videos. The latest addition is the Ruby Object Model and Metaprogramming series by Dave Thomas (of Pickaxe fame). Three episodes are available so far, respectively “Objects and Classes,” “Sharing Behavior,” and “Dynamic Code.” They cost $5 each and clock in at around half an hour each.
With the first episode, Dave starts off at a basic level by covering the history of object-oriented development and taking a look at the core elements of what makes up the object-oriented programming style. He moves on to looking at Ruby specific concerns, metaclasses/eigenclasses, anonymous classes, singleton methods, and the like. He manages to keep things at a level that’s immediately accessible to beginners (lots of diagrams are presented to illustrate concepts and relationships between objects and classes) but isn’t afraid to introduce more complex examples straight after. This is a common pattern throughout each of the screencasts, the contents of which are covered here.
I’d recommend these videos to anyone who wants to quickly get up to speed with the concepts involving classes, objects, and metaprogramming. I don’t believe Dave Thomas has done any screencasting before, but he comes across as a natural. His voice is engaging, eager, and authoritative, which makes the videos very easy to follow without drifting off. Certainly, these screencasts are a superb alternative to the explanations of classes, objects and metaprogramming in most Ruby books. If you’re still unsure, Dave gives a quick 3 minute introduction to the series (video).
Elsewhere: Antonio Cangiano has also reviewed these videos. Check out his review for a slightly different perspective.
Post supported by Ruby Hoedown: Come on down to the south for the Ruby Hoedown, the South’s regional Ruby conference! Submit a talk now or sign up for registration at $199. The first 50 people to use the promo code IMINSIDE will get an additional $25 off the price!

The Pragmatic Programmers (who brought us the “Pickaxe“) have decided to branch into screencasting with Pragmatic Screencasts. At launch, screencasts for Expression Engine, OS X Core Animation, Erlang, and Rails are available. On the Rails front, Ryan Bates (of Railscasts fame) has been brought on board to create a series called “Everyday Active Record.” So far two episodes, each focusing on a different area of Rails / Active Record, are available (at $5 each) but more are promised over time.
The first two episodes are “Designing Models with Associations” and “Finding and Scoping Models.” I’ve watched both and they do a great job of taking a chunk of Active Record / Rails functionality and demonstrating the “right” way to use it. Ryan’s vast experience makes the screencasts good demonstrations of how to use Rails “properly.”
The screencasts are certainly not for anybody who follows Rails Edge like a hawk and keeps on top of everything Rails, but for those who’d like to gain extra confidence from seeing a Rails master at work with Rails 2.1’s features, they’re a bargain. They’re well produced, go along at a nice pace, and Ryan makes a good narrator. I look forward to seeing more from this series in future. Definitely consider checking them out, especially if you want to support Ryan for the hard work he does with Railscasts.
It’s also worth noting that the Pragmatic Programmers are also looking for other people (see bottom question) who might be interested in working with them to produce more screencasts. They do the post-production and pay 50% royalties.
Post supported by Ruby Hoedown: Come on down to the south for the Ruby Hoedown, the South’s regional Ruby conference! Submit a talk now or sign up for early registration for $50 off. The first 50 people to use the promo code IMINSIDE will get an additional $25 off the price!

Slapp: A simple chat wall Merb tutorial is a perfect example of the sort of tutorial / guide that could encourage a lot of people to try out a new framework (as far as Merb is new, of course). It walks you through the process of developing a “chat wall” type application with Merb from start to finish (right from installing Merb to playing with the running application).
One thing that makes the tutorial stand out is that it puts test spec driven development at the heart of the application. After installing Merb and configuring the database, you’re straight into writing a story with RSpec! This is quite different to most of the Rails introductory articles which skim over testing, and it makes the guide very suitable for those who aren’t familiar with RSpec but who want to learn how to use it while developing a Web application.
Lastly, the “finished” application is available from a Gitorious Git repository for those who want to work backwards or look at the code up front.

If you couldn’t get to the popular MountainWest RubyConf two weeks ago, don’t fear. In conjunction with Confreaks, videos of all of the presentations are available to watch online. 14 videos are available, including the following:
Strengthening the Ruby Ecosystem Part I: Rubinius by Evan Phoenix - Evan gives a general overview of Rubinius, how the project has worked out so far, and what the goal is with its development.
Strengthening the Ruby Ecosystem Part II: Merb by Ezra Zygmuntowicz - A similarly general overview of Merb, a Ruby Web applications framework. A great executive overview of the Merb project generally.
Code Generation: The Safety Scissors of Metaprogramming by Giles Bowkett - Giles looks at the beauties (and dangers!) of meta programming and other voodoo with Ruby. This is a particularly interesting talk, and an ideal one to watch if you’re short of time.
Faster, Better ORM with DataMapper by Yehuda Katz - An overview of the DataMapper ORM, a compelling alternative to ActiveRecord.
Deep Ruby by Jeremy McAnally - A look at Ruby’s object model and other “deep” Ruby issues. This is a pretty interesting talk too, for those who like to look at the nitty gritty.
BDD with Shoulda by Tammer Saleh - Shoulda is a great, small, simple testing plugin for Rails applications with a BDD flavor.
Lightning Talks by Various - The lightning talks include Mike Moore doing a “Binary Lottery” program with _why’s Shoes, Chris Shea talking about “Guessmethod“, Ed Moss talking about Active Scaffold, and more.
It seems MountainWest had a really high quality level of talks, so give it a thought when choosing which Ruby events to attend next year.
(On another level, I’m kinda surprised by how many Rubyists seem to have ended up working in groups - whether ThoughtBot, ENTP, or Engine Yard.)

If you’re a Rails developer you will, I hope, be familiar with Ryan Bates’ Railcasts, an amazing site chock full of free Rails related screencasts, and just over a year after posting the first video, Ryan has released video #100, entitled “5 View Tips”, which presents five quick tips relating to your use of views in your Rails applications.
To celebrate a solid 13 months of top-notch screencast production, Ryan has collaborated with a number of sponsors to launch a Railcast 100th Episode Contest.
The contest’s “grand prize” includes an iPod Touch (!), a Code Spaces Subversion hosting plan, a Harvest plan, a $50 Pragmatic Programmers coupon, a $50 Amazon gift card, and a $50 iTunes gift card! The rest of the prizes, all the way down to 9th place, include lesser amounts of most of the same items (as well as some Peepcode goodies).
But what do you have to do to get the goodies? Easy. Write 5 Rails tips, share them with the community by May 5th, and send the URL of where they are to an e-mail address provided on the contest page. Also feel free to post the URL into the comments on this post. It won’t constitute an entry (you need to e-mail Railscasts to do that) but I might link to some of the best entries myself, and it’ll also allow other Ruby Inside readers to enjoy your hard work. Good luck!

Dominiek ter Heide has put together a great tutorial that walks you through building a “Twitter agent” using Ruby, Rails and XMPP. For those who aren’t on Twitter yet, it’s a free micro-blogging cum “presence” information service that allows users to write 140 character messages that are supposed to represent their current state / feelings / location / etc. A Twitter agent, therefore, is essentially an automated Twitter user that can deliver information to other Twitter users.
The tutorial is quite in-depth with lots of code examples and helpful diagrams. Dominiek explains it all very directly, and even has the developed service running for real, so you know you’re seeing something that actually works.

Merb is a Ruby Web framework that most Ruby and Rails developers are familiar with, even if they haven’t used it. Merb is a Model View Controller based framework, somewhat like Rails, but it’s significantly lighter, faster, and more customizable. Merb’s strength is that it has a lightweight core and relies on plugins, selected by the user, to provide most of the extended functionality.
This post is to summarize some of the more interesting Merb tutorials and references, so that newcomers to Merb, or those who want to refresh their knowledge, can get started quickly:
Official Stuff
Merb’s official homepage - The typical launching point for learning about what Merb is, and for accessing stable and trunk builds or learning how to contribute to the project.
Merb’s official API documentation - RDoc generated documentation, straight from Merb’s source code. The main page demonstrates how to install Merb, get a basic application started, and how the main concepts, such as models, views, and controllers, work.
Merb Features - The official list of Merb’s features.
Merb 0.5 Release Notes - The release notes for the latest (as of February 2008) release of Merb.
Merb’s source code repository trunk - A view of Merb’s official git repository at github.com. If you want the latest version of Merb, and live on the edge, get it from here.
Motivation / Rationale / Advocacy
Merb (and why you potentially should care) - A well written demonstration of why Merb matters and Merb’s key features.
Merb-tastic - A general overview of Merb from a non-official point of view. Unspace, a Canadian Ruby consulting firm, takes a look at what Merb is, how it can use different ORMs, and what their motivations for using Merb are.
Introductions / Tutorials / Installation
Merb + DataMapper + Noob: Quick Start - A great introductory tutorial for newcomers to Merb, demonstrating how to create a note taking / simple blog application from start to finish.
Merb Tutorial - Another tutorial that’s older, and partly out of date, but the supplied source code has been updated to the latest Merb standards (well 0.4.2, anyway).
Merborial: Getting Started with Merb and DataMapper - Chris Kaukis with the first installment of a very up to date Merb tutorial (February 2008). In this installment, he shows how to install Merb, DataMapper, and some other plugins, sets up an initial Merb application, creates a database, and provides a bunch of links to useful resources.
Merb & DataMapper: Getting Rolling - A quick introductory piece to installing Merb and DataMapper by Justin Pease.
Doing Stuff with Merb
A Quick Jaunt Through Merb’s Framework Code - A blog post by Ezra Zygmuntowicz that takes a look at how Merb processes and handles incoming requests.
Shoes Meets Merb: Driving A GUI App through Web Services - A six page, in-depth article by Gregory Brown and Brad Ediger that demonstrates how to use the Shoes GUI toolkit along with Merb, where Merb provides the data, and Shoes provides the interface.
Taking Merb to Production - Ben Reubenstein looks at how to use Capistrano and Nginx to deploy Merb applications.
Merbful Authentication - A look at a new (as of January 2008) plugin for Merb that provides an easy to use authentication system.
Merb Routing in 0.5 - A great look at how the URL routing system works in Merb 0.5 by Toolman Tim!
File Uploads Via Merb Inside A Rails Application - A three part tutorial showing how to use Merb alongside a Rails application to handle file uploads in an efficient manner. This is what Merb was originally created for.
Merb on AIR - Drag and Drop Multiple File Upload - A slightly old (June 2007) tutorial demonstrating how to use Merb alongside an Adobe AIR powered client to handle file uploads.
The Future and More!
The Road to Merb 1.0 - Robert Bazinet of InfoQ interviews Merb creator Ezra Zygmuntowicz about the future for Merb.
Merb.next - Yehuda Katz, a developer on the Merb team, looks at how things are progressing with Merb up to version 1.0.
A Mega List of Even More Merb Tutorials - For those readers who aren’t satisfied enough by the above list of Merb links, Merbcast.com has put together even more for you!
Ruby
reference
tutorials
compilation
posts
Miscellaneous
Elsewhere

Shoes Meets Merb: Driving a GUI App through Web Services in Ruby by Gregory Brown and Brad Ediger leads us on a six page tutorial extravaganza through not only building a cross-platform GUI app (namely, a pastebin of sorts) using WhyTheLuckyStiff’s Shoes system, but using Rails-killer Merb as a backend for storing the data. It’s an impressive enough effort that Why himself has linked to it and added a few notes of his own (including the provision of a much better illustrative screenshot - as used above).
In related news, yesterday Why announced the launch of a new version of Shoes, known as “Curious.”

JRuby: An Introduction is a fresh new article by Chris Duckett that presents a practical, code-driven introduction to JRuby, a Java implementation of Ruby. It's the perfect introduction for people who, perhaps, have an idea of what JRuby is, but who haven't yet tried out any of the Java connectivity. The first page looks at interacting with basic Java libraries / classes, with the second moving on to building a basic Swing-powered GUI app using Java APIs from Ruby code.
Added: There's also a screencast by Brian Chapados called Intro to JRuby that's worth watching for a more practical, real-time look.

Introduction to Ruby is a well produced set of four videos by Lucas Holland that provide an introduction to both Ruby and object oriented programming itself. The first video looks at what Ruby actually is and how it handles OOP concepts. The second video covers Ruby's installation. The third looks at some of the tools and programs that come with a regular Ruby installation, and the fourth looks more into actually writing some code and processing data.
Welcome to the first "Interesting Ruby Tidbits That Don't Warrant Separate Posts"! This is going to be a somewhat regular feature of all the reasonably interesting things I'm e-mailed about or discover that aren't getting as much attention as they should, but which aren't captivating enough to warrant an entire post on their own. So without further ado..
thread-dump library
thread-dump is an interesting library that lets you to get a dump of thread activity when a Ruby process quits by Greg Fodor. In his own words:
It allows you to send a SIGQUIT to a ruby process to get a dump of the running threads to STDERR or a file. This is *incredibly* useful for diagnosing hung or slow processes, since you can introspect the ruby process on demand. This is a feature built into the JVM, and has always been an essential part of the diagnostic toolkit.
Using 64 bit primary keys with Rails migrations
Got an app that needs more IDs than the standard 32 bit amount? MySQL can use BIGINT columns, but, as Sanjay Vakil says, "it is a little tricky to convince Rails and Migrations to use it." So Sanjay has come up with a set of instructions and code on how to solve the problem.
How to customize attachment_fu file names
attachment_fu is one of the most popular "file upload" plugins for Rails applications nowadays, but it can prove a little tricky to work out how to get it to use custom file names. Patrick Crowley to the rescue with plenty of code!
Using Amazon S3 from Amazon EC2 with Ruby
Exactly what it says in its title. A great, comprehensive article by Jack Herrington.
Webistrano - Easier Capistrano Deployment

Webistrano is a Web-based interface for managing Capistrano deployments by Jonathan Weiss. There are two screencasts available to demonstrate its use.
10 Reasons to Learn Ruby
A well written, comprehensive look at ten reasons to learn Ruby. I didn't post this separately as it's going to be second nature to most Ruby Inside readers, but it's a good read that deserves some eyeballs nonetheless.
macaddr - MAC address retrieval library
macaddr is a cross-platform library by Ara Howard that lets you retrieve the MAC network interface addresses from the local machine. Just use gem install macaddr and then require macaddr in and use Mac.addr and Mac.addr.list. Works on OS X, Windows and Linux.
Classifier is a Ruby gem developed by Lucas Carlson and David Fayram II to allow Bayesian and other types of classifications, including Latent Semantic Indexing.
Bayes classifier is a probabilistic algorithm which apply Bayes’ theorem in order to learn the underlying probability distribution of the data. One popular use for this is implemented in most spam filtering packages.
It can also be applied to many other cases of machine learning to make your Ruby application more intelligent (the complicated implementation is transparently handled for you, thankfully!) Ilya Grigorik recently posted an interesting tutorial on Bayes classification, with an easy-to-follow demonstration on how to use it for distinguishing between funny vs. not funny quotes:
require 'rubygems'
require 'stemmer'
require 'classifier'
# Load previous classifications
funny = YAML::load_file('funny.yml')
not_funny = YAML::load_file('not_funny.yml')
# Create our Bayes / LSI classifier
classifier = Classifier::Bayes.new('Funny', 'Not Funny')
# Train the classifier
not_funny.each { |boo| classifier.train_not_funny boo }
funny.each { |good_one| classifier.train_funny good_one }
# Let's classify some new quotes
puts classifier.classify "Peter: A boat's a boat but a box could be anything! It could even be a boat!"
puts classifier.classify "Stewie: Damn you ice cream, come to my mouth! How dare you disobey me!"
puts classifier.classify "Brian: I could take my sweater off too, but I think it's attached to my skin. "
puts classifier.classify "Peter: Hey, anybody got a quarter? Bill Gates: What's a quarter? "
puts classifier.classify "Peter: I had such a crush on her. Until I met you Lois. You're my silver medal. "
puts classifier.classify "Meg: Excuse me, Mayor West? Adam West: How do you know my language? "
puts classifier.classify "Meg: You could kill all the girls who are prettier than me. Death: Well, that would just leave England. "
Alternatives and other useful resources: bn4r (article), Bishop, Microsoft Belief Network

Data Structures and Algorithms with Object-Oriented Design Patterns in Ruby is an online book (free to read!) by Dr. Bruno R. Preiss, an incredibly well qualified engineer and computer scientist. It covers all of the various data structures and algorithms that beginning Computer Science students have to learn, but from a Ruby perspective and using object oriented design patterns.
The book itself is now a few years old, but I've only just come across it and it still seems relevant although, rather sadly, the on-page code is in graphics only (a ZIP file containing the source is available) and feels like a line-by-line conversion from C++ rather than true Ruby code. Still, if computer science, data structures, and algorithms elude you to any degree, and you want to learn about them while following Ruby code, it's a good place to start. There are also versions for C++, Java, C# and Python available from Bruno's homepage.

Decentralized identity system, OpenID, appears to be the latest flavor of kool-aid permeating the Rails universe. OpenID makes it possible for users to identify themselves by using URLs that relate to a site where they have already logged in. Your application can then check this with the remote site and then use that status to tie that confirmed identity to their identity within your system. As much for my own reference as anything else, here are the main bits and pieces floating around regarding Rails and OpenID lately:
1) David Heinemeier Hansson started off by talking about how 37signals are looking at using OpenID.
2) Dan Webb wrote an excellent tutorial, "The No Shit Guide To Supporting OpenID In Your Applications", showing how to, well, use OpenID within Rails applications.
3) Ben Curtis demonstrates how to tie in OpenID with the popular Acts As Authenticated plugin.
4) The OpenID Authentication plugin wraps around the Ruby-OpenID gem and makes OpenID integration from Rails simple. Code examples are provided.
5) John Nunemaker points us to the Ruby on Rails wiki page for OpenID that provides links to several other resources.
6) Way back in the summer of 2006, EastMedia and Verisign developed a Rails-based open source OpenID server that was released under the Apache Heraldry project. Verisign use it to power their PIP system.
7) Dag Rorek Arneson built a Rails OpenID guestbook that's still available (but very slow) at http://rorek.org:3001/.
NEW! 8) Bernie Thompson has put together a kick ass page of Rails and OpenID resources as well as a screencast that quickly demonstrates the power of OpenID.
Austrian development agency, Sparkling Studios, look at how to use the Akismet anti-spam system to check data submitted to your site and protect your application from spam. It works by signing up for a key from Akismet and using a Ruby Akismet library. Then whenever you want to check your data, you make a simple call and Akismet returns a true or false based on whether the system believes the data to be spam.
It should be noted that this method is primarily useful for blog comment and trackback related spam, but could be useful on other data that fits the same structure.
Most init.d start-up scripts seem to be bash scripts, but you can write them with any language. Here's some template code I use to create my own Linux services. You can even add them to chkconfig to be started properly on startup, and they'll also work with RedHat / CentOS's service system straight off.
#!/usr/bin/env ruby # # app_name This is a startup script for use in /etc/init.d # # chkconfig: 2345 80 20 # description: Description of program / service APP_NAME = 'app_name' case ARGV.first when 'status': status = 'stopped' puts "#{APP_NAME} is #{status}" when 'start': # Do your thang when 'stop': # Do your thang when 'restart': # Do your thang end unless %w{start stop restart status}.include? ARGV.first puts "Usage: #{APP_NAME} {start|stop|restart}" exit end