What happens when your code breaks in production? If you have Honeybadger you'll be alerted with crucial details like the error location, the data being processed and the affected users. So you can deploy a fix quickly and get back to coding. Learn more.

RubyFlow The Ruby and Rails community linklog


The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

What are real-world prime examples of good Ruby code?

A Ruby Inside reader wrote in last week asking me to run an article linking to projects they could look at that demonstrate good Ruby style and coding practices (after I had said Heist was a good demonstration of this). So.. rather than just post all my own opinions, I thought I’d get some input! What libraries, apps, plugins, etc, do you think show a very high quality of coding? All suggestions welcomed, and if you leave a name/URL with your comment I’ll try and credit you in the article.


I really love the clarity and style of coding of Thin - http://github.com/macournoyer/thin (Marc-Andre Cournoyer has done a great work!)

There are several other quality code I have seen, let me dig my github watch list for you..

Scott Baron’s AASM library (http://github.com/rubyist/aasm/tree/master) is another good example which shows how to modularize and abstract a library. Also, it is covered with good spec.

As many of you already would agree Sinatra code base is another masterpiece - http://github.com/bmizerany/sinatra

I cast my vote for DataMapper.

They use coding style guidelines, require specs for new features or behaviour and have split the project into multiple libraries to reduce maintenance over-head.

I like reading the Merb or Datamapper code, it’s the main source of documentation for these big frameworks:



I vote for 2 gems that have really impressed me recently. Both extremely good implementations! I’ve loved studying the code.

pluginaweek: http://github.com/pluginaweek/state_machine/tree/master

authlogic: http://github.com/binarylogic/authlogic/tree/master

I would have said DataMapper also but the YARD documentation instead of plain old RDoc isn’t such a hot idea IMO.

+1 for reading Merb source code.

If you’re less interested in good code and more in the mood for a puzzle, I loved reading the source code for Camping for the first time and figuring out everything :) http://github.com/why/camping/blob/master/lib/camping-unabridged.rb

I’ve not dug around too much into gems and plugins but I always thought paperclip was easy to read and understand.

At least, easier to read and understand than attachment_fu and file_column.


I’m the maintainer of DataMapper, so it’s nice to see the work our contributors do appreciated. I should mention though that the repository for DataMapper was moved to http://github.com/datamapper/dm-core/ a few weeks ago. The master branch is ok, but then next branch is even cleaner, and we’re working on improving it further since it will be the basis of the next 0.10.x series.

@Norm I can understand why you don’t like YARD. It’s all valid rdoc syntax, but it looks terrible when converted to HTML using standard rdoc tools. Where it really shines though is using the yardoc tools – you get a nice HTML document showing the types and descriptions for every input argument, and return value. When I’m reading through the code I find this much more useful than just textual descriptions of methods. Now that I’ve used YARD on a decent sized project I can’t imagine going back to plain rdoc.

As far as other projects with clean code go, I’d like to cast my vote for Merb: http://github.com/wycats/merb/

@Dan Merbs documentation is still RDoc and shows parameters, types and return values using simple list items with a description?

Here’s a vote for Ramaze. Clear, concise code, with plenty of helpful rdoc comments which are replete with examples.

I’d say Prawn’s code is one of the best examples of really refined Ruby which come to my mind. Moreover: a) it’s not just “by accident or virtue”. Prawn’s code seems to be written with being an example of polished Ruby code in mind, b) it’s not a huge codebase, b) it’s well known problem domain (draw shapes/text/etc on screen).

If you are looking for a good example on how to write (r)specs, I recommend checking out Merb’s extlib (something like ActiveSupport for Rails, but smaller). I didn’t have a look at the implementation code, but I guess it’s pretty good too.

Thanks for the tips!

Once you have a glance at those evaluations, anyone might certainly makeup their thoughts to purchase rolex wrist rolex replica. Are you desperately waiting for your husband to glare to you, consider having a replica rolex? It will be calculates.Many have a captivation to possess a large assortment of watches. After that rolex Submariner Watches timepieces should also be a part of your own collection. They also have wrist watches with diamonds inside it.

I am a beginner, and I want to begin reading good code so that I don’t get in the habit of writing bad code. I listened to a podcast today on Ruby Rogue, and for about 5-7 minutes, they were speaking about the importance on writing small methods. I thought it might be a good place to start.

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in