Ruby Inside

Syndicate content
Updated: 1 hour 21 min ago

Cucumber: The Latest in Ruby Testing

Wed, 11/19/2008 - 19:35

Testing is a firmly ingrained part of the Ruby culture: you probably ran across Test::Unit not long after you first started writing Ruby code (though it wouldn't be surprising if you ignored it for a while). But it hasn't been a static part of Ruby - we've seen the simple availability of tests evolve into test-driven development (TDD) that in turn gave rise to behavior-driven development (BDD). Along the way, Ruby has spawned a variety of testing tools and frameworks. The latest, Aslak Hellesoy's Cucumber, is the latest addition to the RSpec family of tools.

Cucumber is designed to allow you to execute feature documentation written in plain text (often known as "stories"). I've been experimenting with it as a replacement for integration tests in Rails. With Cucumber, you can write tests that look like this:

Scenario: See all vendors Given I am logged in as a user in the administrator role And There are 3 vendors When I go to the manage vendors page Then I should see the first 3 vendor names

With Cucumber, that it an executable specification that you can discuss with the customer and then use to verify the correct behavior of tests. Behind the scenes, you make it work by writing "steps," which are regex matchers that execute Ruby code. Here's one of the steps for that scenario:

Given /there are (\d+) vendors/i do |n| Vendor.transaction do Vendor.destroy_all n.to_i.times do |n| Factory.create(:vendor, :business_name => "Vendor #{n}") end end end

Ideally, you'll do this all in true BDD fashion: write the Cucumber features first, watch them fail, implement code to make them pass (with lower-level tests written with RSpec or Test::Unit), and repeat.

Cucumber is under rapid development, but it's already a useful part of my testing toolbox. In addition to integrating with RSpec and Rails, it works with Merb, Sinatra, and the Webrat web-testing framework (as well as, of course, pure Ruby projects). It also has translations into 20 languages and the ability to run FIT-style tabular tests. If you're looking for a higher level of abstraction in your tests, it's definitely worth checking out.

Supported by: ActionGear is a menu-bar app for task management on your Mac. It's lightweight, quick, and helps you get stuff done. Try it out for free.

Scaling Ruby - The Informative, 40 Minute Screencast

Mon, 11/17/2008 - 01:41

Earlier this month, Rails Envy's Gregg Pollack gave a talk at RubyConf08 called Scaling Ruby (without the Rails). He answered questions like "How do existing Ruby applications use Threads/Processes to scale?", "How do we implement an Event Driven application using Ruby EventMachine?", "What are the current bottlenecks with speeding up Ruby and how can they be fixed?", and "What does Ruby 1.9 bring to the table to speed things up?" From what I hear, it was a very well received and informative session.

Not all of us could be at RubyConf08, however, so Gregg has taken the whole Ruby scalability topic and put together a solid 40 minute screencast called Scaling Ruby (note: it is NOT a recording of the talk - but a separate, professional production). It costs $9 (cheaper than RubyConf, of course) but it's a very solid primer on Ruby scaling issues. Almost every topic is illustrated through Gregg's unique diagrams, and he goes into depth on topics as diverse as event-based applications, threads, Rinda, process messaging, and even "dropping in to C" to write high performance sections of code.

I've been very impressed with the quality of the EnvyCasts I've seen so far, and this is no exception. Lots of practical knowledge delivered in a memorable way. $9 will still seem too rich to many - especially those who think all forms of documentation and instruction should be free (as in speech and beer) - but if it takes Gregg and Jason's fine commercial attempts to encourage others to produce higher quality, free documentation, I'm all for it! They also have screencasts covering Rails 2.2 (see the Rails Inside review) and ActiveRecord.

(Disclaimer: I've received free, promotional copies of the EnvyCasts for review. I have no other relationship - financial or otherwise - with the Rails Envy guys, other than being one of the first to promote them back in the day - doesn't time fly!)

Ruby Best Practices: The Book and Interview with Gregory Brown

Fri, 11/14/2008 - 15:42

Back in March, Ruby developer Gregory Brown raised the idea of receiving donations so he could work on open source Ruby projects full-time. It went well, and out of this project came Prawn, a pure Ruby PDF generation library. Not one to rest on his laurels, Gregory's now working on a book for O'Reilly called Ruby Best Practices, billed as "for programmers who want to use Ruby the way Rubyists do." The book will cover how to design "beautiful" APIs and DSLs, along with lots of other general topics that will make your code more expressive and make you a better Ruby developer into the bargain.

The book is not due for final release until August 2009, but thanks to O'Reilly's "Rough Cuts" program, the first three chapters (Driving Code Through Tests, Designing Beautiful APIs, and Text Processing and File Management) are already available. Online-only access is $17.99 and you'll get the latest version as it becomes available. Print-only and Print + Online bundles are also available.

Gregory gave me a copy of the first three chapters to look over, and they're well crafted. This definitely isn't a reference book, a "cook book" or any sort of book you merely "dip" into. It's designed to be read by the chapter. The first chapter, Driving Code Through Tests, for example, takes you on a journey through the world of testing in Rubyland from motivation through to best practices - it's a full introduction to a single topic.

The Interview

I decided to ask Gregory a few questions to get more background on the book, as well as an update on his Ruby Mendicant project:

What was the inspiration for writing Ruby Best Practices?

Right now, it's entirely possible for one to learn enough Ruby to get by without ever understanding why people love the language. I think one reason is that our books have disproportionately emphasized on solving particular problems, via some recipe or pattern. We've also got a ton of introductions to the language, some better than others, but these books don't dive into code that looks or feels real. Our reference books are great (at least IMO), but they're only telling you what sharp tools are in the shed, not how to use them.

Ruby Best Practices is a book about why Rubyists tend to write Ruby the way they do. So this book looks at a lot of real code, most of it from open source projects, and tries to make it approachable to any reader who's got a reference book handy, so long as their willing to engage their brain a bit. I'm hoping that people will have fun learning a bit more about the 'why' behind a lot of the design decisions we face when writing code.

Does the rapid pace of change in the Ruby community makes writing a book like this more difficult?

I think change is generally good, and that folks who wish to live on the edge must be willing to pay the price. There's nothing wrong with using older versions of software if you're not ready to make the jump to the new hotness of the week.

However, I want this book to be current when it prints, and I also want to help encourage people to move forward, so I've been writing against Ruby 1.9.1 only. Because the only place 1.8 is mentioned is in my chapter on how to write backwards-compatible code, I don't have the pain that most people do with updating their notes constantly about changes in 1.9 vs 1.8. I just need to make sure my code keeps running properly on 1.9.1 until the time the book is released. There are hiccups from time to time, but I've definitely been in less pain than anyone who's trying to write a reference book right now.

What sort of developer should be buying this book right now?

I think that any developer who has worked through some introductory Ruby material and has a reference book handy can learn something from RBP. I've got a couple internal reviewers who are in exactly that position, so they help keep that target audience in range.

However, in terms of the Rough Cuts release, what I need most is folks who are fairly strong in idiomatic Ruby to pick up a copy and help correct me where I am wrong. I put together a great team of internal reviewers who check every chapter before it becomes public, but more eyes will surely help shape the book before it hits the shelves.

I definitely want the book to have the kind of authority that comes from extensive peer review instead of having people trust it based on name recognition. If people provide feedback through Rough Cuts, I think it'll be easier to accomplish that goal.

How is the Ruby Mendicant project going?

The Ruby Mendicant project officially ended on September 30th, two weeks after the scheduled end-date. However, I'm still actively working on Prawn and will continue to move things forward over the coming months. I came up a little short of the hours I initially pledged, but accomplished most of the goals I had in mind. We're getting closer and closer to providing a replacement for PDF::Writer, and many users have already made the jump.

I gave a talk on Ruby Mendicant / Prawn at RubyConf, and it's probably the best summary I've done so far, which people could check out once Confreaks gets the video online. I also plan to write a post-mortem about the whole experience but haven't found time just yet. I'll link it on that talk page once it's available.

Roxy - An Object Proxying Library for Ruby

Thu, 11/13/2008 - 17:10

When you want your objects to refer to / have associations with other objects, it can quickly become a complex procedure. Ryan Daigle to the rescue! Ryan has built Roxy, a "Ruby Proxy-Object Library." He's also put together an awesome blog post with the motivation for developing Roxy and some code examples showing how it works. Roxy gives you the ability to add some rather ActiveRecord-esque functionality to your classes and their instances.

Straight from the horse's mouth:

Roxy is a basic proxy library that lets you quickly create proxies between your ruby objects. Its syntax is loosely based on Association Extensions in ActiveRecord as that is a well-known use of proxies.

Still not convinced to jump straight over to Ryan's blog post? Code example coming up in 3..2..1..:

class Person include Roxy::Moxie attr_accessor :first, :last, :parents proxy :parents do def divorced? proxy_target.size > 1 and proxy_target.collect { |parent| parent.last }.uniq.size > 1 end end end # Can then invoke your proxy methods directly on parents person.parents.divorced?

Supported by: ActionGear is a menu-bar app for task management on your Mac. It's lightweight, quick, and helps you get stuff done. Try it out for free.

Easy Git External Dependency Management with Giternal

Wed, 11/12/2008 - 14:46

Anyone building up a project with many dependencies - and in the Ruby community, with so much functionality wrapped up in gems and plugins, it's hard to imagine not having external dependencies! - must face the issue of managing the situation in source code control. How do you maintain everything you need in your own repository, while still being able to update your dependencies from their own repository? How do you set things up so you can even contribute to the projects you depend on?

If you're using git, the right answer is often the subtree merge strategy - but remembering the necessary commands can be a nuisance, especially if you rarely use them. There are several projects out there designed to make this easier for you: Tim Dysinger published some rake tasks to handle subtrees, and Braid is a more full-featured tool to manage both git- and svn-based vendor branches. 37signals have also released cached_externals which provides a somewhat different solution to the problem using symbolic links and separated checkouts.

After trying all of those approaches, though, I've settled on Pat Maddox's giternal tool for my own work. With giternal, you add a YAML file with details on your project's dependencies, similar to this:

delayed_job:   repo: git://github.com/tobi/delayed_job.git   path: vendor/plugins paperclip:   repo: git://github.com/thoughtbot/paperclip.git   path: vendor/plugins

After that, there are just three commands to remember: giternal update to update all of your dependencies, giternal freeze to create a self-contained deploy tag with all externals at a known version, and giternal unfreeze to go back to live subtrees. If you've been shying away from dealing with externals in your git repositories, give it a shot.

Merb 1.0 Released So Here’s 44 Links and Resources To Get You Going

Sat, 11/08/2008 - 21:14

Merb - a much heralded, highly flexible Ruby-based Web application framework - has reached version 1.0 after two years of development. Congratulations to Merb's creator, Ezra Zygmuntowicz, and to the large group of associated developers (such as Yehuda Katz and Matt Aimonetti) who've kept adding features and pushed Merb forward to be a significant alternative to Rails.

Ruby Inside has been some surveys for the past couple of months, and they still show that only 25% of Ruby Inside's visitors have ever developed a Merb application. With the stability that the 1.0 release offers (older versions of Merb had a reputation - fair or not - for a constantly shifting API), it's now a great time to give Merb a try. It's also a great time to get into writing tutorials and documentation!

Quick Start

Install Merb from Rubyforge: gem install merb

If you'd rather go from Merb's "edge" repository: gem install merb --source http://edge.merbivore.com

NOTE: Make sure that you are running RubyGems 1.3.0 or higher (run gem -v to check). If not, you need to upgrade (I found this page very useful for doing that.

Then follow a tutorial such as Life On The Edge with Merb, DataMapper & RSpec, Slapp: A Simple Chat Wall Merb Tutorial or Move Over Rails. Here Comes Merb.

Once you're ready to roll, bookmark this page for safe keeping and read on for our Merb resources! We've divided them up into sections to make it easier. Some will also be left in the comments by other readers!

Merb News and Community Sites

Merbunity - A community news site that focuses entirely on Merb. So far it's not been updated particularly often, but this is likely to change, and what they do have is great.

Merbivore - The official Merb homepage. It provides links to all of the major things you'd need - docs, a wiki, downloads, and information on how to help the Merb project.

Merb Overheard - A "planet" / aggregation blog for Merb related content. It also features some of the latest Merb related Twitter messages. A good looking site and well worth following if you want to stay up to date on Merb news.

Planet Merb - A "planet" site for Merb-related blogs. Currently only has the blogs of several Merb developers and the official Merb blog, but it's bound to grow over time.

The Merbist - A Ruby Inside-esque blog for the Merb world. It's run by Matt Aimonetti, a Merb core team member. Well worth subscribing to if you want a look at high level news related to Merb.

Merb Google Group - A Google Groups hosted mailing list for Merb developers. It has over 800 members and is pretty busy!

#merb on irc.freenode.net - Not a Web link, but an IRC channel. If you want to chat live about Merb but aren't familiar with IRC, learn more here.

Ezra Zygmuntowicz's Brainspl.at - The personal blog of Merb creator, Ezra Zugmuntowicz. A lot of it is Merb related in some way or another.

Katz Got Your Tongue? - The personal blog of Yehuda Katz, a key Merb developer and evangelist. A lot of Merb related posts.

Merb Tutorials and Documentation

Note that some tutorials may be slightly out of date or use features that have changed in Merb 1.0. Use these tutorials as a guide, not as canon (for that, you'll want a book, see next section).

The Merb Book: Life On The Edge With Merb, Datamapper & RSpec - An online book started by the guys of London development team, New Bamboo, but now contributed to by many Merb developers. It's very indepth and changing over time. There's definitely no lack of detail here.

Merborial: Getting Started with Merb and DataMapper - A simple and straightforward tutorial by Chris Kaukis.

Move Over Rails. Here Comes Merb. - A tutorial by Mark Watson that demonstrates how to create a "planet" type Ruby blog aggregator using Merb. Very complete - doesn't include Ruby Inside though? Heresy!

Relax with Merb and CouchDB - A very clean and to the point guide by Paul Carey on developing a Merb application that uses CouchDB for the DB backend (using RelaxDB).

7 Merb Questions Answered - Justin Pease answers some Merb related questions. How to access environment variables, partial rendering, how to use HAML, how to start in production mode, how to log data, and how to get the current URL in a view.

Slapp: A Simple Chat Wall Merb Tutorial - SocialFace presents a great tutorial on how to use Merb to develop a basic "chat wall" application. If you'd rather just look at the resulting code, check out the Slapp Git repository.

Merb + Shoes = Interesting Web / GUI App Crossovers - Gregory Brown and Brad Ediger wrote a six page tutorial on how to develop a cross-platform GUI app using Shoes and Merb on the backend.

Multi Environment Merb+DM Deployment with Vlad+Git - Corey Donohoe (a.k.a. atmos) demonstrates how to use Vlad and Git to deploy your Merb apps.

MerbCamp Videos - Videos of all of the main sessions from MerbCamp. Lots of awesome stuff to watch here on how to write Merb plugins, how to deploy a Merb app, Merb primers, DataMapper tutorial sessions, how to migrate from Rails to Merb, and more!

MerbAuth - The Basics - An excellent overview of the MerbAuth authentication framework and how to use it to perform authentication in your Merb app.

Merb Books

Merb in Action - A general Merb book being written by Michael Ivey, Yehuda Katz, and Ezra Zygmuntowicz. It's not due out in print till May 2009, but so far three chapters are available in PDF form via an "Early Access Edition" right now. With the soldier on the cover, I guarantee this will end up being called the "MIA" or "Soldier" book :)

The Merb Way - Following in the mold of the awesome The Ruby Way and The Rails Way books will come The Merb Way by Foy Savas. Publishing date is still uncertain, but likely to be next year. Given the history of Addison Wesley's * Way series, I expect this will be a gigantic reference book spilling out all of the guts of Merb for us to see and enjoy.

Beginning Merb - Apress continue their Beginning * series with a Merb entry. Due out in February 2009, it'll be about 500 pages in length.

Merb Sample Apps

Feather - An "uber lightweight" Merb blogging engine / system. A blog is always a great app to take inspiration from :)

Panda: Open source video platform - An open source video transcoding and streaming platform built mostly around a Merb app.

PmpknPi - A RESTful Blog API written in Merb.

Slapp - A "chat wall" Web app.

Merb-OpenID-Example - An example OpenID consumer application written in Merb using merb-auth's OpenID functionality.

merb_mart - An open source e-commerce engine built on Merb.

merb-dm-couchdb-sample - A quick sample application showing how to use CouchDB with a Merb / DataMapper app.

Merb Events

MerbCamp - MerbCamp was the first official gathering for the Merb community, but it's likely to happen again next year, so make sure you keep your eyes peeled for it. Also be sure to watch the videos of the MerbCamp presentations.

MerbDay - A Merb event taking place in Atlanta on December 6. Yehuda Katz will be speaking.

Merb Outpost - A London based "outpost" of MerbCamp where 29 Merbists watched MerbCamp on a live webfeed. I'd be surprised if they didn't try to revive this for the next MerbCamp. If you're in London and want to be in contact with other local Merbists, however, get on there and check them out.

Merb Miscellaneous

FiveRuns TuneUp for Merb - FiveRuns is a leading provider of monitoring and development products for Ruby on Rails and other popular open source and commercial systems. They've got a version of their performance tuning and debugging tool, TuneUp, available for Merb developers.

Google Tech Talk: Merb, Rubinius and the Engine Yard Stack - Ezra Zygmuntowicz gave a tech talk to Googlers on Merb and Rubinius. This is very new and well worth watching for its full 47 minutes.

A Quick Jaunt Through Merb's Framework Code - Ezra Zygmuntowicz presents a tutorial for those who want to see how a request travels through the Merb framework in its quest to get a proper response. Some nice indepth stuff here.

Merbcamp - notes from the edge - Some excellent notes taken based on what happened at Merbcamp.

Authlogic - A framework agnostic authentication system that works well with Merb. Get awesome authentication on your Merb app - fast.

Merb on RubyForge - All of the Merb libraries and gems directly from RubyForge.

Merb on Github - All of the Merb libraries collectively within a Git repository on Github.

DataMapper - While Merb forces no specific ORM on you, DataMapper has become the de facto standard when developing Merb applications. Learn more about it here.

Merb TextMate bundle - A Merb bundle for TextMate by Dr Nic Williams.

Merb_global - Localization and internationalization support for Merb. Experimental.

merb_cucumber - A library offering Cucumber (a BDD testing tool) integration with Merb.

21 Merb Links, Tutorials and Other Resources - A set of Merb resources on Ruby Inside from February! Might still be some stuff worth checking out in there. It's a real bran tub of Merb delights.

Why Engine Yard, Rubinius and Merb Matter - Antonio Cangiano looks at some of the motivation behind Engine Yard's progress on Merb and Rubinius.

Got any more Merb resources? Please leave a comment!

3 Tools for DRYing Your Ruby Code

Fri, 11/07/2008 - 21:03

We've all heard the admonitions: "Don't Repeat Yourself!" But how do you avoid this if you're working on a Ruby codebase that stretches to thousands of lines, maintained by multiple developers? One answer is to run a tool that looks for duplicate code. This is an area where good tools are tantalizingly close - there are at least three out there that are worth checking out:

Towelie

The first contender is Giles Bowkett's Towelie, which uses parsetree and ruby2ruby to look through a set of files searching for duplicates. Unfortunately, Towelie in its current state was unable to handle my test case (the Active Record subtree of Rails), persistently erroring somewhere in parsetree. Admittedly, ActiveRecord is an extremely large and often arcane code base - though yours may be also.

Giles has written an extensive blog post on Towelie, which includes a screenshot of a successful output. Clean and to the point. Give it a try and see if it works on your code base - there's a lot of potential here.

Flay

Next I looked at Flay, which just showed up (instantly at version 1.0.0) on RubyForge. From Ryan Davis, Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. It's capable of detecting both exact and close matches, and did in fact find some spots in Active Record where patterns repeat. In its current state, Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up.

Just gem install flay, and then flay *.rb to get playing with Flay.

Simian - A more general approach

Turning away from pure Ruby tools, I grabbed a copy of Simian, a code similarity analyzer that's been around for quite a while. Written in Java, Simian can handle Ruby source code just fine - and indeed, it very quickly found a number of duplicate lines in the source I was looking at. For open source projects, Simian is free; others will pay $99 or more to license. This is definitely a more mature and faster tool than either Towelie or Flay; the drawback is that it has no knowledge of Ruby code structures, and so can't do the sort of logical looking for duplicate intent that the native tools promise.

Conclusion

The verdict? If I were coming into a new codebase with suspicious provenance, I'd run all three tools against it to get a sense of how bad the situation is. But I'd love to see the Ruby community push along the two native tools to a point where they have better output and can actually be used in a nightly build to watch for problems. We're not there yet, but could be reasonably soon - thoughts?

Rubyists On The Front Row of Election History

Wed, 11/05/2008 - 02:12

Happy Election Night!

A few days ago, the Obama campaign ran another call for donations and offered the chance for ten donors to sit on the "Front Row to History" - basically the front row of an Obama event in Grant Park, Chicago. Rubyists Bruce Williams (of FiveRuns) and Damon Clinkscales (Austin on Rails) have made it into this group, and they've rapidly launched The Tweet Row to History (obamaftw.org) - a Twitter fuelled site with their up-to-the-minute adventures in Chicago.

Naturally, Bruce and Damon are flying the Obama banner pretty strongly, but this is a bipartisan site, so may whoever you voted for win!

RubyMine: A New “Intelligent” Ruby IDE Built on IntellJ

Tue, 11/04/2008 - 06:11

RubyMine is an all new IDE for Ruby and Rails developers, developed by JetBrains (best known for Java IDE IntelliJ IDEA). RubyMine is built upon the IntelliJ IDEA platform and brings together all of the essential features you'd expect of an IDE (editor, debugging tools, source control integration, code completion, and so forth) along with lots of extra goodies specific to Ruby, such as GUI-based support for RSpec and Test::Unit.

The current release of RubyMine is billed as a "Public Preview" with a full release set for Q1 2009. This public preview is free to use for 30 days and JetBrains are keen to elicit feedback on their RubyMine forum in that time. As a commercial developer tools vendor, I suspect JetBrains will most be charging for RubyMine when it's finalized. The pricing for IntelliJ IDEA is £450 ($599 - oddly) for a "commercial license" and £187 (or $249) for a "personal license" - just to give you an idea of the level JetBrains operates at.

On a casual tryout of RubyMine, I found it to be a little smoother than Eclipse based IDEs, and although it's clearly not a fully native OS X application (in terms of widgets) it looks pretty good. It took several minutes for my first Ruby project to be created as it was busy parsing all the Ruby files on my system for some reason, but once this was done, further projects were created instantly. Up and running, the IDE seemed to do the trick, but I didn't go too far as I'm not a big fan of IDE-based development. This was on OS X only, so your mileage may vary.

In any case, it's interesting to see another "everything but the kitchen sink" cross-platform Ruby IDE to compete with RadRails and NetBeans, but if RubyMine becomes a commercial application priced similarly to IntelliJ IDEA, I can't see it becoming popular except with devoted IDEA users migrating to Ruby, but hopefully JetBrains will pull something interesting out of the bag to make it a more interesting proposition.

Supported by Media72 Hosting: Looking for reliable UK Ruby on Rails hosting? Packages start from just £7/month on our mod_rails/apache stack hosted on fast UK servers and include free 24/7 support.

Latest Ruby and Rails Events News: November 2008

Mon, 11/03/2008 - 04:08

Here's the latest events news in the Ruby and Rails worlds as of November, 2008. Please comment if you have other events to mention - people will see them, and we can possibly mention them on the next post:

RubyConf08 - November 6-8, 2008 - Orlando, FL, USA

RubyConf celebrates its 8th birthday! This eighth international Ruby conference takes place at the Omni Orlando Resort at Championsgate in Orlando, Florida later this week. You can stay at the resort itself and enjoy three full days of Ruby conference goodness. The schedule looks ridiculously good - except Giles Bowkett got taken off the speakers list because some of the organizers wouldn't understand what a sense of humor is even if it slapped them in the face. No tickets left, but there's a waiting list - just on the off-chance that hundreds of angry Giles Bowkett fans quite rightly tear up their tickets in disgust.

North West Ruby User Group Pub Meet - November 20, 2008 - Manchester, UK

The NWRUG is a popular Ruby user group in the North West of England - the home of entertainer Frank Sidebottom. They're looking to spread the word and extend their influence further though, so if you're in the North West of England, get your arse down to The Paramount on Oxford Street in a couple weeks' time and have a pint of Boddingtons for me. If, however, you're like me and live in the North but are too lazy to drive across the Pennines, check out Leeds Ruby Thing instead.

acts_as_conference 2009 - February 6 & 7, 2009 - Orlando, Florida, USA

acts_as_conference is a Florida-based Rails conference. Last year was a success - selling out all 150 tickets. Currently the 2009 conference is in planning. 175 tickets will be up for grabs this time - the venue will be better and breakfast and lunch will be supplied on both days of the conference. Organizer Robert Dempsey has just put out a call for papers, so if you want to give a presentation there, get to the official site and let them know. The deadline for talk proposals is November 30.

Atlanta Merb Day - December 6, 2008 - Atlanta, Georgia, USA

The Atlanta Ruby Users Group presents Merb Day, a single-track conference geared towards Ruby and Rails developers who’d like to dive into Merb, a hacker’s framework. Atlanta’s first Ruby conference, Merb Day is an opportunity to exhibit Ruby’s strengths to the city’s growing technology economy. Michael Ivey and Yehuda Katz will be among the attendees and tickets are $65.

Voices That Matter: Professional Ruby Conference - November 17-20, 2008 - Boston, MA, USA

The Voices That Matter: Professional Ruby Conference will "provide practical, people-oriented and in-depth information about using Ruby and the Rails platform to create dynamic technology solutions." Obie Fernandez heads a solid speaker list including Ruby and Rails luminaries like Giles Bowkett, Thomas Enebo, Hal Fulton, Chad Pytel, Tammer Saleh, Ezra Zygmuntowicz, and others.

Registration is still open and costs $995. Supposedly if you use the promotional code PRZSPNS you get a $200 discount (for a total of $795)! (Disclaimer: Ruby Inside is cross promoting with Pearson. No money, but Ruby Inside's logo features in their promotional materials.)

Ruby Fun Day - November 22, 2008 - Sector 59, Noida, New Delhi, India

Are you in India? Can you get to New Delhi? Do you like fun? Do you like Ruby? Answer yes to all of those questions and you could go to Ruby Fun Day in the intriguingly named "Sector 59" area of Noida, India. It's billed as a "day full of Ruby fun" with an emphasis on showing and demonstrating code and cool Ruby projects. I quite like the sound of that.

Ruby’s New FFI Library: Calling External Libraries Just Got A Whole Lot Easier

Sat, 11/01/2008 - 18:36

Charles Nutter, of the core JRuby team, writes:

One of the largest problems plaguing Ruby implementations [..] is the ever-painful story of "extensions". In general, these take the form of a dynamic library, usually written in C, that plugs into and calls Ruby's native API as exposed through ruby.h and libruby.

The many compiled bridges between external libraries and Ruby pose a problem for alternate implementations like JRuby, because of the complexity involved in exposing internals of the implementation or expensive serialization in both directions. Instead, an interface is necessary so that instead of developing libraries that act only as unique bridges to others, we can just have one library that provides the interface to any arbitrary library of our choice.

Ruby already has a library called "dl" that makes it possible to dynamically link external libraries with Ruby. It's a bit arcane though, and Charles points out that it's not widely used "because of real or perceived bugs." Given this, and given the need for an implementation that can be compatible with JRuby, Wayne Meissner has developed "FFI", a new Ruby library that provides "Foreign Function Interface" features to Ruby.

A basic demonstration of a Ruby script that uses C's getpid function should be enough to demonstrate the simplicity of FFI:

require 'ffi' module GetPid extend FFI::Library attach_function :getpid, [], :uint end puts GetPid.getpid

The best part? FFI is available for Ruby 1.9, Ruby 1.8.6 and 1.8.7 (just gem install ffi), as well as JRuby 1.1.4 (and above) and Rubinius (Rubinius's implementation is separate to Wayne's, but works similarly). Wayne has also written a blog post with his side of the story. He says he's waiting to "see how people are actually using it in the real world."

This FFI implementation has the hallmarks of becoming a new Ruby standard for calling out to external, compiled libraries. Let's get behind it, start using it, and crank out some code to see how it operates!

Nokogiri: A Faster, Better HTML and XML Parser for Ruby (than Hpricot)

Fri, 10/31/2008 - 17:50

Yesterday, Aaron Patterson (@tenderlove) and Mike Dalessio released Nokogiri (Github repository), a new HTML and XML parser for Ruby. It "parses and searches XML/HTML faster than Hpricot" (Hpricot being the current de facto Ruby HTML parser) and boasts XPath support, CSS3 selector support (a big deal, because CSS3 selectors are mega powerful) and the ability to be used as a "drop in" replacement for Hpricot.

On an Hpricot vs Nokogiri benchmark, Nokogiri clocked in at 7 times faster at initially loading an XML document, 5 times faster at searching for content based on an XPath, and 1.62 times faster at searching for content via a CSS-based search. These are impressive results, since Hpricot was previously considered to be quite speedy itself. (Update - November 3, 2008: WHY FIGHTS BACK! HPRICOT IN PERFORMANCE BUSTING SHOCKER!!)

The code examples provided on the introduction post give you the basic idea, and the library can be installed using gem install nokogiri (though this didn't work for me on OS X - further instructions below).

Installing on OS X

Note! Developer Aaron Patterson responded to the issues below in an update to the library. Now doing a regular gem install of Nokogiri should work fine. The information below is remaining in place solely for historical / reference purposes.

Upon trying sudo gem install nokogiri, I encountered multiple problems on OS X. Perhaps it'll work first time for you, but if not, here are some pointers. (Bear in mind, I run the default Ruby that comes with OS X - no special configurations. If you're running Ruby from DarwinPorts, etc, the following might not work at all.)

Trying to install the gem failed after "checking for racc... no". I assumed it was trying to download and install racc by the following line, but it's not. You need to download and install racc yourself. The latest tarball for that is at http://i.loveruby.net/archive/racc/racc-1.4.5-all.tar.gz - download this, and open a Terminal. Continue along these lines:

tar xzvf racc-1.4.5-all.tar.gz cd racc-1.4.5-all sudo ruby setup.rb config sudo ruby setup.rb setup sudo ruby setup.rb install

Trying to install the gem at this point still won't work, as for some reason the racc executable has ended up in /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin rather than /usr/bin proper. My solution to that was to add that directory to my path in ~/.bash_profile - but you might prefer to symbolically link it. Your choice. If you have no ~/.bash_profile and you're following these instructions blindly, just put this in ~/.bash_profile:

PATH=$PATH:/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin export PATH

Next, something called "frex" is also missing. This is more easily installed with gem:

sudo gem install aaronp-frex -s http://gems.github.com

Once this is done, then nokogiri should finally install with gem:

sudo gem install nokogiri

Run up irb and give require 'nokogiri' a try to make sure.

Please leave any corrections, suggestions, or cries for help in the comments. Thanks!

What’s Hot on Github - October 2008

Thu, 10/30/2008 - 11:42

What's Hot on Github is a monthly post highlighting interesting projects that are new or updated this month, within the Ruby community that are hosted on Github. Github 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.

This month's picks:
  • seinfield - Track your open-source contributions with Github.
  • suprails - A funky new substitute for the "rails" command.
  • nokogiri - A hpricot alternative that boasts better speed.
  • astrotrain - "Scans incoming emails for mapped recipients and sends an HTTP POST somewhere."
  • friendly_id - "monkey patched friendly_id that allows for a larger number of duplicate slugs". Includes remembering past slugs.
  • acts_as_sayable - "Rails plugin to provide text2speech functionality over models."
  • flash-message-conductor - A simple pattern for managing flash messages in your Ruby on Rails application.
  • formtastic - A Rails Form Builder with semantically rich and accessible markup.

A special thanks this month goes to the Rails Rumble team as they made some great suggestions based on what people had used for their applications.

Have any projects to add or want to recommend a project for next month's post? Please leave a comment.

Ruby 1.9.1 Preview Released: Why This Is A Big Deal

Wed, 10/29/2008 - 17:04

In an understated post on the official Ruby blog last night, Yugui (Yuki Sonoda) announced the release of Ruby 1.9.1-preview 1.

Why To Get Excited

A preview release? Why is this a big deal? A few reasons why Ruby 1.9.1 is significant, even as a preview release:

  • Ruby 1.9.1 will be the first stable, production-ready release of the much anticipated Ruby 1.9 series.
  • The Ruby 1.9 branch is the cornerstone of Ruby's future. Much as PHP 5-style code is replacing PHP 4-style code, Ruby 1.9's idioms and style will eventually reign (even if it takes a few years).
  • As of Ruby 1.9.1-preview 1, the language features and changes are effectively "frozen." Changes to standard libraries for multilingual features are likely to continue, however.
  • Ruby 1.9.1-preview 1 allows you - as a developer - to test your code and libraries on what will eventually become the "default" Ruby.

On that last point, as Dave Thomas says in his release summary:

If you are the maintainer for any publicly available Ruby code (be it a Gem, an application, or whatever) I strongly urge you to download this preview. You'll be doing the community a great service in two ways. First, the various incompatibilities between 1.9 and 1.8 mean that there's a chance that your code may not work without some tweaks. Making those changes now will help others using your code.

Getting Ruby 1.9.1-preview 1

You can get Ruby 1.9.1-preview 1 in source form from the official ruby-lang.org FTP site at ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-preview1.tar.gz or via HTTP from http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-preview1.tar.gz

If you find the ruby-lang.org server slow - as I do - I've made the .tar.gz available here from Amazon S3, so you should be able to download it at full speed.

Ruby 1.9 Resources

When Ruby 1.9 was still quite new, James Edward Gray wrote the excellent "Getting Code Ready for Ruby 1.9." Much of it is still very relevant.

Almost a year ago, Sam Ruby wrote a comprehensive set of notes on porting REXML to Ruby 1.9.

Mauricio Fernandez's gargantuan "Changes in Ruby 1.9" is still an excellent reference.

Got any Ruby 1.9 migration tips or tricks of your own? Please, leave a comment!

Supported by: ActionGear is a menu-bar app for task management on your Mac. It's lightweight, quick, and helps you get stuff done. Try it out for free.

A List of Non-English Ruby and Rails News Sites

Tue, 10/28/2008 - 05:55

When Ruby Inside started over two years ago, there were only a handful of sources for Ruby related news. The announcements on the ruby-talk mailing list (which Ruby Weekly News - now deceased - rounded up on the Web), del.icio.us, and a few popular Rubyists blogs (such as Why's Redhanded). Now, however, there are lots of options, including Ruby Inside itself, Rails Inside, RubyFlow, Ruby Reddit, and Planet Ruby on Rails.

But what about the Ruby and Rails news for non-English speakers? I've been keeping my eye on a number of foreign-language Ruby and Rails news sites, and want to highlight some of the best:

Russia / Россия / русско

RubyFlow.ru is a Russian equivalent of the English language RubyFlow.com. Like RubyFlow, it's a community blog where news about Ruby and Rails libraries, projects, tutorials, and so forth can be posted.

They've done an excellent job on the design - it rather makes me wish I could read Russian!

RubyMag is a new weekly summary of Ruby and Rails news for Russian speaking developers.

The Netherlands / Dutch / Nederlands

RubyWeb is a Dutch RubyFlow clone. There seem to be posts for most days, and it's primarily updated by "TomEric" of i76.

Ruby En Rails is a Dutch Rails-themed blog. It doesn't seem to be particularly well updated, but has news relating to Dutch Rails events, along with general tutorials written in Dutch.

China / 中国

Flow.RubyNow.com is a Chinese language equivalent of RubyFlow. It seems to mostly feature the same items as RubyFlow but in Chinese.

Japan / 日本 / 日本語

RubyFlow-ja is a Japanese language translation of RubyFlow, and the first such translation. It's maintained by Makota Kuwata - of Erubis fame. It features the most interesting of the RubyFlow stories (that is, not all of them).

The Rubyist is a long-time Japanese language online Ruby magazine. It has a very strong reputation in the Japanese Ruby community, but as the articles aren't translated into English, many Anglophone Rubyists are not aware of it. It's not to be confused with Jeremy McAnally's newer print-based The Rubyist magazine.

Indonesia

For some time, the official Indonesian Ruby site featured translations of choice Ruby Inside articles into Indonesian. This appears to have stopped recently, but it is still a key resource for Indonesian Rubyists.

Brazil / Brasil / Portuguese / Português

Ruby-Br.org is a key resource for Brazilian Ruby developers. It summarizes a lot of general Ruby news in Portuguese.

Akita on Rails is a Brazilian Rails-focused blog written by perhaps the most famous Brazilian Rubyist of all - Fabio Akita (who was the principal organizer of the successful Rails Summit Latin America conference recently).

Others? I Need Your Help!

I've been trying to find Ruby news sites in other popular languages, such as French and German, but have been drawing blanks. Where are French, German, Swedish, Danish, Spanish and Italian Ruby developers getting their news from? I want to turn this post into a resource for finding foreign language Ruby news sites, so please leave your links and suggestions in the comments.

Ruby Style Guides and Tools: How to Write Good Looking Ruby

Mon, 10/27/2008 - 11:43

Last week, Noel Rappin of Pathfinder Development wrote Elements of Ruby Style - an attempt at producing a Ruby "style guide." After some initial feedback to this, he's followed up with a response to some of the initial criticisms and suggestions.

Noel isn't the first to try to develop a Ruby style guide. In an attempt to promote Ruby's use within Google, Ian Macdonald wrote an extensive Ruby style guide back in 2006 (rather sadly, it appears his attempt did not work out).

What's a "Style Guide" then?

For those unfamiliar with style guides, the most famous for the English language are probably Strunk & White's The Elements of Style and The Chicago Manual of Style (my personal favorite) - both attempt to define how to write and lay out English texts properly. Style guides for programming languages, however, usually attempt to not only define the "correct" way to write and lay out code but also the right idioms to use in certain situations.

Other Tools

Ruby style and "code smells" have become topics of interest for many Ruby developers recently:

  • Last month, Kevin Rutherford released reek, a "code smells detector"
  • Marty Andrews released Roodi, a tool that checks Ruby code for complexity
  • flog is also a popular Ruby tool for testing and showing the complexity of your Ruby code.

Supported by Media72 Hosting: Looking for reliable UK Ruby on Rails hosting? Packages start from just £7/month on our mod_rails/apache stack hosted on fast UK servers and include free 24/7 support.

Merb 1.0 RC2 Now Available: Merb 1.0 Not Far Behind!

Fri, 10/24/2008 - 12:39

Following on from the highly successful MerbCamp, the Merb Framework took another big step this week with the announcement of the availability of release candidate 2 for it's upcoming 1.0 release (due within weeks now). No major changes and The Merbist blog lists mainly a focus on bug fixes and Windows compatibility:

The main focus for this release was to fix bugs and make the stack Windows compatible. We didn’t get any major bugs in RC1 but fixed a lot of small annoyances and problems with generated resources. We also made sure Merb itself would work properly with Windows (not using incompatible signals etc..) and we spent some time getting the Data Object sqlite3 drivers compiled on Windows.

Seems like a great time to begin playing around with Merb if you haven't yet. You can install / update Merb through RubyGems using sudo gem install merb

Ruby Inside is planning to run a resource packed feature on Merb when it hits 1.0, so keep your eyes peeled!

Support from: 1st Easy offers UK Rails hosting (dedicated and shared) running Phusion Passenger (mod_rails) and LAMP stack. If you want to get to know us first, or simply want to evaluate the performance of your Rails applications running on Passenger, we'll arrange a trial hosting account for you (full technical support included!)

Mobile Orchard: Like Ruby Inside, but for iPhone Developers

Wed, 10/22/2008 - 15:03

A brief aside to mention my latest project (in collaboration with Dan Grigsby) - Mobile Orchard.

Mobile Orchard is a new iPhone developer news site, in a similar vein to Ruby Inside. We've already:

There's a lot of money and a lot of excitement about the iPhone development community right now. Hampton Catlin says he's around the 48-50 mark in the "Top Paid iPhone App" list and he's selling 1,000 copies of his application each day, so if you can get into the top 10, you're going to be running a very serious business indeed.

Anyway, if you're an iPhone developer or are just interested in the platform, get over to Mobile Orchard and, ideally, subscribe to the feed or follow us on Twitter. If you don't want to do any of those things but want to wish us luck, you can do so in the comments here or save us on del.icio.us :)

How To Develop A Mac (Cocoa) Application With MacRuby And XCode

Mon, 10/20/2008 - 12:33

Over a year ago we had a post about how to build OS X GUI applications with Ruby and RubyCocoa. Since then, however, MacRuby has arrived on the scene. Not just the regular version of Ruby with some bindings to Cocoa, MacRuby is as native to OS X as JRuby is native to the JVM.

It's a significant development, then, that Apple has created a very in-depth tutorial called Developing Cocoa Applications Using MacRuby. It's very comprehensive. The tutorial introduces you to MacRuby, walks you through installation, demonstrates Objective-C bindings, and steps through using XCode and MacRuby to develop a simple GUI application. If you want to read a single tutorial and be able to develop a Mac GUI app with Ruby from start to finish, this is currently the tutorial to read.

That said, you might still appreciate our Ultimate List of RubyCocoa Tutorials, Tips, and Tools. There are 42 links there; many of which are still incredibly useful.

Working With Video From Ruby

Fri, 10/17/2008 - 15:26

With only the performance of a scripting language, Ruby isn't considered a particularly suitable choice for intense video work (direct transcoding, encoding, and the like.). Nonetheless, there are a handful of Ruby libraries and Ruby-based technologies you can use to work with video and movie files - primarily through interacting with faster tools or libraries.

RMov (Ruby Quicktime Library)

RMov is an awesome new Ruby library by Ryan Bates that wraps around Apple's QuickTime API and allows you to open, edit, and export QuickTime movies from within Ruby. It is, unfortunately, OS X only.

RVideo (Ruby Video Processing)

RVideo (Github) is a Ruby library that interfaces with tools like ffmpeg to let you inspect and process video and audio files. For example, you can use RVideo to help you convert videos into FLVs.

Panda (Video Encoding and Streaming Platform)

Panda is a Ruby-powered open source "video uploading, encoding and streaming" solution. While it uses Ruby as an interface (in the shape of a Merb application), it relies on tried and tested tools like FFMpeg to do the heavy lifting but may be perfect if you have an Amazon EC2 account and fancy offloading the CPU intense video work.

Hey!Spread (Video Promotion Web Service)

Hey!Spread makes it easy to upload videos to YouTube and Google Video - each operation essentially becoming a method.

Fliqz4R ("White-Label YouTube" API)

Fliqz is a provider of "plug and play video solutions." Effectively they provide the backend infrastructure for hosting and playing videos, a kind of white-label YouTube, if you will. Libin Pan has put together a tutorial that demonstrates how to use Fliqz from Ruby / Rails using the Fliqz4R Rails plugin.

Any other libraries to recommend? Leave a comment.