Learning Ruby for Force.com Developers – Part 1

December 30, 2010 Appirio

With salesforce.com’s recent purchase of Heroku, Ruby just got more interesting. I’ve never dabbled in Ruby (although I’ve wanted to!) so this is an excellent reason to dig into the language and see what it’s all about. Since I’m learning Ruby I thought some people might also benefit from the experience and make the learning curve a little less steep.

So today we’re kicking off a series on getting started with Ruby and Heroku. I’m not sure how many posts there will be but I hope to post something every week on the subject. We welcome any input you might have to make this journey easier. I know there are some Ruby experts in the salesforce.com community so please keep us honest and on the right track. Here are the goals of the series:

  • Learn Ruby
  • Develop an app locally using Ruby on Rails and the SQLite database
  • Modify the app to use Database.com and the Force.com Toolkit for Ruby instead of the SQLite database
  • Deploy the app to Heroku


For this series we’re assuming that you have some type of basic programming background, have no knowledge of Ruby (I certainly don’t), are using a Mac (sorry PC guys/gals but most of the difference is simply setup and configuration) and have a little time to experiment and learn.

Technology Overview

So with any new technology there is a lot of stuff to learn and digest. Here are some key aspects that you should know:

Ruby – Ruby is an object-oriented interpreted scripting language created by Yukihiro Matsumoto (more affectionately known as Matz) in Japan starting in 1993. Ruby is an interpreted language (similar to PHP, Python and JavaScript) that is compiled when it is executed. Languages like Java and C++ are pre-compiled into a binary before being executed. Ruby is very portable, elegant and somewhat easier to learn. The disadvantage, since it is an interpreted language, is that it runs slower than equivalent compiled applications and your source code is visible to anyone using your application. Wikipedia has a really good, quick overview of the language and syntax.

RubyGems – RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries (in a self-contained format called a “gem”), a tool designed to easily manage the installation of gems, and a server for distributing them. You will use RubyGems to install new programs and libraries on your computer.

Ruby on RailsRoR is an open source web application framework developed by 37Signals of BaseCamp fame. Like many web frameworks, RoR uses the Model-View-Controller (MVC) architecture pattern to organize application programming. RoR includes tools that make common development tasks easier “out of the box”, such as scaffolding that can automatically construct some of the models and views needed for a basic website. Also included are WEBrick, a simple Ruby web server that is distributed with Ruby, and Rake, a build system, distributed as a gem. RoR also uses ActiveRecord (an object-relational mapping system) for database access.

GitGit is a distributed revision control system similar to Subversion or CVS. You don’t need Git to develop Ruby applications however I believe you will need Git to push your application to Heroku. Git is really gaining ground lately and I believe that saleforce.com is moving Code Share to github.com.

Installing Ruby

Depending on your platform, Ruby may or may not be installed already. If you are using a somewhat newer Mac then Ruby should be installed. Open Terminal and type ruby –version. You should see something like the following.

The current stable version of Ruby is 1.9.2 but I have 1.8.7 installed and it seems to be working fine for now. If you’d like to download a newer version you can do so from here. If you are on a PC, then you can use the RubyInstaller.

Interactive Ruby

Now that you have Ruby installed it’s time to start getting serious. Ruby comes with a program called “Interactive Ruby” (IRB) that will show the results of any Ruby statements you provide it. Playing with Ruby using IRB like this is a great way to learn the language. To get started open Terminal and type irb. On Windows, open fxri from the Ruby section of your Start Menu.

Now for the obligatory “Hello World”. Type puts “Hello World” and hit enter. There you go. Your first Ruby program.

Dig into Ruby

Now it’s time to really dig into the Ruby language. Here are some links that I’ve found helpful in order that I would recommend.

  • Ruby in Twenty Minutes – I would start with this intro first.
  • Try Ruby – An interactive tutorial that lets you try out Ruby right in your browser. This is a cool tutorial but it “seemed” to crash on me a number of times.
  • Ruby Essentials – a free on-line book designed to provide a concise and easy to follow guide to learning Ruby.
  • Ruby Koans – These are a series of files that you download and run locally to learn the language, syntax and structure.
  • Hackety Hack – A fun and easy way to learn about programming (through Ruby) using the Shoes GUI Toolkit.
  • Ruby Documentation – A great list of Ruby references. Pick and choose from here.

If anyone has any suggestions for other helpful sites please chime in. Spend some time using Ruby and I think next time we’ll get into Ruby on Rails.

Previous Article
Loading Data to Salesforce.com with the Bulk Data API using Talend
Loading Data to Salesforce.com with the Bulk Data API using Talend

Ward Loving Talend has recently acquired the capability of inserting data using the new Salesforce.com Bulk...

Next Article
Salesforce Cloudstock Hackathon Demo from Dreamforce 2010
Salesforce Cloudstock Hackathon Demo from Dreamforce 2010

Jeff Douglas This is the demo that I put together for the Cloudstock Hackathon and I tried to throw in as m...