Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easy Ruby libraries to understand for beginner [closed]

Tags:

ruby

I'm at the point in learning Ruby where I'd like to look at some small-ish libraries' source code to see how they were built. I do not know what is considered a small library but was hoping SO could recommend some easy-to-understand libraries to study.

So if anyone knows a very tiny library or two that's a good example for novice Rubyists to study, please recommend!

I wanted to use Manveru's Innate lib because it tries to stay under 2000 LOC but I'm not yet familiar with the Ruby shorthand that is used so much within it.

Maybe some ~100 - ~500 LOC libs would be better for me? Thank you.


1 Answers

Ryan "ZenSpider" Davis's stuff is always interesting. It is however, not entirely suited for beginners. On the one hand, Ryan is absolutely fanatical about keeping things, simple, short and clean, which helps understandability quite a bit. On the other hand, he does use pretty much all of Ruby's power to achieve that.

One of the most amazing examples of his work, is MiniTest, the new testing framework which replaces Test::Unit in the Ruby 1.9 standard library. It contains a full xUnit style testing framework in 419 lines, an RSpec style BDD framework in 87 lines and a full mocking framework in a whopping 28 lines.

But, for example, the way that the BDD framework is so small, is that it uses reflective metaprogramming to dynamically loop over the assertion methods from the testing framework and rename them to BDD style must_ methods.

Another nice example is also a BDD framework by Christian Neukirchen: Bacon has 291 lines. Also check out his other stuff, for example his mocking framework in 131 lines, forum software in 488 lines and blog engine in 146 lines.

Last but not least, there is Gregory Brown's Prawn PDF Generation library. The interesting thing about Prawn is actually that it was deliberately written not only as a PDF Generation library but also as an example of well-written, well-designed Ruby code. Again, his other stuff is also interesting, like his blogging engine in 184 lines.

Speaking of Greg Brown and well-written code: Greg is the author of the book Ruby Best Practices, which uses real-life code examples from real-life Ruby projects to show what good, well-written, well-designed Ruby code looks like. (Plus, it also has a chapter called Ruby Worst Practices with anti-examples.) And, you don't even have to buy the book (although you really should), because all the code samples are on GitHub!

like image 114
Jörg W Mittag Avatar answered Jun 18 '26 05:06

Jörg W Mittag