Diving into Ruby just about a year ago, I faced many challenges and unfamiliar concepts in the Ruby ecosystem. Things like testing, gems, the who’s who of the community, rake, rdoc, web stuff like Sinatra and Rails were all very confusing. It was a rewarding experience, but the search involved a lot of trial and error. This article hopes to clear the air a bit, and give a clear and comprehensive introduction to Ruby, its community, its ecosystem, and the tools Rubyists use.
The Idea of Ruby
Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write. – ruby-lang.org
Ruby is a language that emphasizes simplicity. It attempts to eliminate verbosity and clutter. Rubyists tend to favor terse code that convey intent clearly and concisely.
5.times do puts "This is beautiful and readable" end
You can read that. I would bet my last paycheck that you can read and understand what it does. There is no clutter and no needless jargon. There are no unnecessary parentheses or symbols. It is simple, clear, and concise.
This is integral to the very nature of the Ruby community. Verbosity and clutter are abhorrent to Rubyists ( though some still don’t get it). There are also generally accepted style guides. The community has evolved an aesthetic so refined that they pay attention, not only to intent and productivity, but even to the way Ruby code lays out on a screen.
For a comprehensive view of idiomatic Ruby and how you should write Ruby code. Eloquent Ruby by Russ Olsen is a wonderful reference.
Lets have a look at some of the primary Ruby Community members.
Yukihiro Matsumoto: The Creator of Ruby
Yukihiro “Matz” Matsumoto created Ruby in the mid-1990’s. He is the person behind most of the decisions that make Ruby what it is today. Matz still leads the development of the language’s reference implementation, MRI (for Matz’s Ruby Interpreter).
You can follow him on Twitter at @yukihiro_matz.
David Heinemeier Hansson: The Creator of
Ruby on Rails
David Heinemeier Hansson created Ruby on Rails (Ruby’s most popular web framework) from his work on Basecamp. He released the framework as open source in July of 2004. He’s decisive and very vocal about his views. DHH’s (as he is known in the community) ideas are a large part of what has made Rails what it is.
You can follow him on Twitter at @dhh.
Aaron Patterson: Ruby and Rails Core Contributor
By day, Aaron Patterson is a mild mannered programmer for Red Hat whose Ruby code is almost as good looking as him. By night, he dons his Pink Warrior suit which gives him the power to contribute to many Open Source projects such as nokogiri, Ruby, and Rails. If you have seen someone kissing Matz or DHH at a conference, it was probably him. – Ruby on Rails Core
I probably couldn’t explain Aaron’s cool weirdness better than that.
There are many more amazing people in the Ruby Community. You’ll meet them along your journey. As a bit of homework, go read about Sandy Metz, her great presentations, and her amazing book.
Gems and Dependency Management
Dependency Managers provide an easy way to manage the libraries you use. Most modern programming languages have dedicated Dependency Managers. For example, PHP has Composer, Node.JS has npm, and Ruby has RubyGems.
A Ruby library is called a
gem. You can install a gem on your system (if you have Ruby installed) with:
sudo gem install <gemname>
(you may not need
This command will install the library into the global Ruby installation, but what if you want to install certain gems for just one project. Here comes Bundler.
Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are required.
To use Bundler, create a
Gemfile in your project root and list the gems you need (
bundle init will create the file for you).
Here’s an example
source "https://rubygems.org" gem "rails" gem "nokogiri" gem "odyssey"
To install all the gems in the Gemfile, run:
from the project directory.
You can even create gems easily with bundler. To read more, check out RubyGems
Unlike many other languages, the Ruby Community places a great emphasis on testing. Automated Tests allow you to run one command and know, know, that everything in your application is working. Tests improve your design and give you a simple “It works” check. If you don’t know how to write tests in Ruby, check out this SitePoint Screencast.
If you want to be a competent Ruby developer and release your code to the world, you are going to have to write tests. Believe me, testing will make your life and the lives of your co-workers much better.
Rails, Sinatra, and the Web
If you haven’t noticed, Ruby is a general purpose programming language and not just a scripting language like PHP. So, Ruby can be used for almost anything. But one of the most popular uses of Ruby, is web development, partially because
Ruby On Rails makes it ridiculously easy to get it done.
Rails is a full-stack web application framework. It encourages convention over configuration, which means it provides the architecture and expects certain things to be a certain way. With that convention comes a lot of power. As a result of phenomenal leadership and a clear vision, Rails is one of the most popular web application frameworks in the world.
But what if you don’t want a giant full-stack framework. In cases when you just want to create a few routes or when you don’t need the power that Rails provides, use Sinatra.
Sinatra is a micro framework that gives you a lot of flexibility, but not all the power and conventions that come with Rails.
There are a lot of other Ruby web frameworks like Volt, Padrino, and Lotus which are gaining traction, but Rails and Sinatra must be in your toolkit.
Automation with Rake
There are a lot of things that you have to do over and over again while writing Software, like:
- Cleaning up your Gemfile
- Initializing a Git Repository
- Setting up gems for your toolkits, like Bootstrap
With Rake, you can create a task called
rake . You can pass in parameters and do a whole lot of really cool stuff with Rake.
Frameworks like Rails provide default Rakefiles that automate a lot of the tasks associated with web development. For example, in a Rails project you can run:
to view all declared routes in your Rails app or
will migrate (create your tables and other database objects) your database.
To learn more about Rake, check out Rake: Automate All the Things on SitePoint.
Wrapping Things Up
I hope you’re more familiar with the Ruby community and ecosystem now. This should give you an introduction to the Ruby World. So far, you’ve just been wading in the sea. Now that you know the water is inviting, dive in.
A Student/Web Developer/Writer with too much time on his hands. Life Goal: Become Aaron Patterson (@tenderlove)
The Principles of Beautiful Web Design, 4th Edition
Docker for Web Developers
HTML5 Games: Novice to Ninja