Why mobile developers should care about Ruby & its Tooling
Ruby underpins a number of widely used tools used for mobile development, including:
A basic awareness and a level of comfort with Ruby tooling is useful to have.
From the official Ruby website:
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 on Rails
“Ruby on Rails” (or simply ‘Rails’) is a web framework for the Ruby programming language.
Whilst Rails was instrumental in the rise of the popularity of the Ruby programming language, you do not need to use Rails to use the Ruby.
Ruby Version Managers
There are a number of tools in the Ruby ecosystem that let you install and switch between different versions of Ruby on your computer. Some of the more popular ones are:
Hint: Pick one and use only one. I use rbenv.
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. It was created by Chad Fowler and Richard Kilmer during RubyConf 2004
You use and interact with Ruby Gems via the
$ gem list # list installed gems ** LOCAL GEMS *** activesupport (4.2.10) addressable (2.5.2) $ gem install cocoapods # install cocoapods (which is a ruby gem)
A common problem for developers is that the project they are working on requires a set of libraries, of specific versions for that app to work.
To solve this problem for Ruby projects, use Bundler:
Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed. Bundler is an exit from dependency hell, and ensures that the gems you need are present in development, staging, and production. Starting work on a project is as simple as bundle install.
Specifying & Installing Dependencies
When using Bundler you specify your dependencies in a Gemfile in your project’s root directory. Example Gemfile:
source 'https://rubygems.org' gem 'nokogiri' gem 'rack', '~> 2.0.1' gem 'rspec'
Then to install the dependencies specified in the Gemfile:
$ bundle install
bundle install will resolve all the dependencies, install the required gems and (on the first time it is run) generate a file: Gemfile.lock.
The Gemfile.lock lists the full names and versions of all the gems that you have used. Subsequent calls to
bundle install will use the Gemfile.lock to ensure the exact same gems will be used, even if you are running the code on a different machine.
You should check in your Gemfile.lock into version control.
Running code with the Specified Dependencies
You should then use the
bundle exec command to run any executable that comes with a gem from the bundle, eg:
$ bundle exec fastlane
bundle exec to run your command (fastlane) in this case, ensures the specified versions of the Ruby gems will be used to run the command.
Rake is a Make-like program implemented in Ruby. Tasks and dependencies are specified in standard Ruby syntax.
Rake is a ruby gem and installed using:
gem install rake
Rake uses a ‘Rakefile’ which contains build rules. Example:
task default: %w[test] task :test do ruby "test/unittest.rb" end
$ rake # will cause rake to run the default task in the Rakefile $ rake -T # will display the tasks and their description
rake -T (or
rake --tasks to be more verbose) is a good idea when you come across a new Rakefile.
End of File
This concludes our whistlestop tour of the Ruby tooling that you are likely to encounter on your development adventures. Make use of the provided links to dive deeper into any of the tooling as necessary, and bookmark this page for reference.