27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

544 APPENDIX A Why Rails?<br />

with their own code. There are gems such as the json gem, which is used for parsing<br />

JSON data, nokogiri for parsing XML, and of course the Rails suite of gems.<br />

Previously, gems were hosted on a system known as RubyForge which was unstable<br />

at times. In July 2009, Nick Quaranto, a prominent Rubyist, created the RubyGems<br />

site we know today: http://rubygems.org. This is now the primary nexus for hosting<br />

and downloading gems for the Ruby community, with RubyForge playing second fiddle.<br />

The site Nick created provides an easy way for people to host gems that other people<br />

can use, freely. Now isn’t that just awesome?<br />

Working with gems on a project used to be tough. To find out what gems a project<br />

used they had to be listed somewhere, and there were often times when the tools used<br />

to install these gems would not work, either installing the wrong gems or simply refusing<br />

to work at all. Then along came Bundler. The Bundler gem provides a standardized<br />

way across all Ruby projects for managing gem dependencies. It’s a gem to<br />

manage the gems that projects use. You can list the gems you want your project to use<br />

in a special file known as the Gemfile. Bundler can interpret (when bundle install is<br />

run) the special syntax in this file to figure out what gems (and the dependencies, and<br />

their dependencies’ dependencies) need installing and then goes about doing it.<br />

Bundler solves the gem dependency hell previously witnessed in the Ruby and Rails<br />

communities in a simple fashion.<br />

In addition to this, having different Ruby versions running on the same machine<br />

used to be difficult and involve a lot of hacking around. Then another prominent<br />

Rubyist, Wayne E. Seguin, created a gem called Ruby Version Manager (RVM) that<br />

allows for simplistic management of the different<br />

All in all, RubyGems and its ecosystem is very well thought-out and sustainable. It<br />

provides an accessible way for people to share their code in a free manner and serves<br />

as one of the foundations of the Ruby language. All of this work has been done by the<br />

exceedingly great community which is made up of many different kinds of people,<br />

perhaps one day even including people who are reading this appendix.<br />

A.4 Reason #4: emphasis on testing<br />

Within the Ruby and Rails community there’s a huge focus on writing great, maintainable<br />

code. To help with this process, there’s also a big focus on test-driven development<br />

along with a mantra of “red/green/refactor.” This mantra describes the process<br />

of test-driven development: you write tests that are then failing (usually indicated by<br />

the color red), write the code to make those tests pass (indicated by green), and then<br />

clean up (refactor) the code in order to make it easier for people to know what it’s<br />

doing. We covered this process in chapter 2.<br />

Because Ruby is interpreted rather than compiled like other languages, you cannot<br />

rely on compilers to pick up errors in your code. Instead, you write tests that<br />

describe functionality before it’s implemented. Those tests will fail initially, but as you<br />

write that functionality those tests will pass. In some situations (such as tests written<br />

using the Cucumber gem), these tests can be read by people who requested a feature

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!