Learning Ruby for Force.com Developers – Part 1

December 30th, 2010

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 I’m kicking off a multi-part 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. I welcome any input you might have to make my journey easier. I know there are some Ruby experts in the salesforce.com community so please keep me honest and on the right track. Here are my goals of the series:

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

Assumptions

For this series I’m 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:

RubyRuby 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.

RubyGemsRubyGems 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.

terminal.png

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. (I actually just upgraded to 1.9.2 and followed the instructions for Snow Leopard (it was a painless intall) but there are also instructions for Leopard for those needing it.)

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.

terminal2.png

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 Tutorial – a really good tutorial for core Ruby programming
  • 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.

VN:F [1.9.22_1171]
Rating: 10.0/10 (5 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Learning Ruby for Force.com Developers - Part 1, 10.0 out of 10 based on 5 ratings

Categories: Heroku, Ruby, Salesforce

Leave a comment

Comments Feed10 Comments

  1. thecrmninja

    VERY exciting!!! I’m really looking forward to getting oriented with Ruby in a SF-centric way. I’ve been hoping to learn about the language as it’s gaining so much traction in the development community and i’m thrilled that you’ll be sharing the opportunity to do so!

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: +1 (from 1 vote)
  2. Wes

    Dude you beat me to it, I was toadly going to do just such a series!

    Some neat things I’ve learnt so far (on OSX):
    - You can tailor the irb prompt to do some pretty wicked things such as autocomplete and show you if braces/blocks aren’t closed. Check it out here: http://mislav.uniqpath.com/poignant-guide/book/expansion-pak-1.html
    - By far the most entertaining manual on Ruby is Whys (Poignant) Guide. It’s hilarious and is seriously good at explaining programming fundamentals: http://mislav.uniqpath.com/poignant-guide/book/chapter-1.html
    - There is a utility called ‘ri’ which will give you the documentation on any method, library or class. It’s documented in the first link I’ve given.

    The thing I’m digging most about ruby is that it’s:

    a) easy to read
    b) super concise
    c) a scripting and web-oriented language!

    Loving the additional linkage, bookmarked them already :)

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  3. Peter Martin

    Jeff,
    great article and I look forward to the next installments.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  4. Mohammad Swaleh

    Hi Jeff,
    I was looking for something to start Ruby. Now I got excellent start. Thanks you so much.

    Waiting for coming episodes.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  5. Jason

    I hope your endeavors are more successful than mine. I spent nearly a day and a half trying to get basic app up and running on Heroku and it was a complete failure.

    There are so many little idiosyncrasies that you must learn. Setting up PATH variables, moving DLL files to proper location for local databases, generating and placing valid SSH keys, migrating databases. This is madness!!! At least it feels like madness coming from the force.com dev world. Force.com makes building apps ridiculously simple and I’ll echo a tweet I made earlier….Force.com is like Apple. Closed, locked down, and expensive but “just works”.

    VA:F [1.9.22_1171]
    Rating: 4.0/5 (1 vote cast)
    VA:F [1.9.22_1171]
    Rating: +1 (from 1 vote)
  6. Jeff Douglas

    @Jason, I saw your comments on Twitter. Hope we can get it figured out.

    VN:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VN:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  7. Joel Dietz / d3developer

    +1 for the Why guide.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  8. Joel Dietz / d3developer

    I’m also a huge fan of learning by doing. On this, check out Peepcode. Awesome videos for learning tons of stuff (including a lot of Ruby)

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  9. Mayank

    Hi Jeff,

    When you will post your Part 2 .

    Thanks.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  10. Haribabu

    Jeff thanks for u r article, I installed ruby on my system, but i am not able to send set the path to execute “test.rb” files, Can u please suggest the required path settings .Please suggest me jeff.

    Thanks in Advance

    Haribabu

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

Leave a comment

Feed

http://blog.jeffdouglas.com / Learning Ruby for Force.com Developers – Part 1