SlideShare una empresa de Scribd logo
1 de 7
Descargar para leer sin conexión
Ruby: Why We Love It
https://github.com/Kelsin/ruby-presentation
Christopher Giroir
November 8th, 2011
Contents
1 The Language 1
1.1 Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Why We Love It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Gems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2 Tools 6
2.1 Bundler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2 RVM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1 The Language
1.1 Basics
Overview
• Inspired by Smalltalk (which I love)
• Also draws from Perl, Eiffel, Ada and LISP
• Includes a REPL
• Built for developers as a language they would love to use
• Dynamic, strict, reflective, object oriented
• Everything is an expression (even statements)
• Everything is executed imperatively (even declarations)
Object Oriented
• Everything is an object
• Single Inheritance
• Modules can be mixed in
• Dynamic Dispatch
1
Simple Code
1 5.times { print "Hello" }
This outputs:
1 Hello
2 Hello
3 Hello
4 Hello
5 Hello
6 => 5
Types
1 # Strings
2 s = ’Testing’
3
4 # Interpreted Strings
5 t = "Double #{str}"
6
7 # Symbols
8 sym = :chris
9
10 # Arrays
11 a = [1,2,3]
12
13 # Hashes
14 h = { :key => ’value’, :chris => ’awesome’ }
Classes
1 class Box
2 def initialize(w,h,d)
3 @width = w
4 @height = h
5 @depth = d
6 end
7
8 def volume
9 @width * @height * @depth
10 end
11 end
12
13 box = Box.new(2,2,2)
14 box.volume # => 8
Simple Inheritance
1 class JackInTheBox < Box
2 def initialize(msg)
3 @msg = msg
2
4 super(3,3,3)
5 end
6
7 def open
8 puts @msg
9 end
10 end
11
12 jbox = JackInTheBox.new(’Surprise!’)
13 jbox.volume # => 27
14 jbox.open # prints ’Surprise!’
Control
1 while true == false
2 if var == 5
3 break
4 end
5
6 begin
7 var - 1
8 end while var < 4
9
10 next if var == 6
11 end
Blocks
1 [1,2,3].each { |n| puts n }
This outputs:
1 1
2 2
3 3
4 => [1,2,3]
Block Syntax
1 5.upto(10) { |n| puts n }
This is exactly the same as the following:
1 5.upto(10) do |n|
2 puts n
3 end
1.2 Why We Love It
Attribute Methods
3
1 class Person
2 def name
3 @name
4 end
5 def social=(s)
6 @social = s
7 end
8 def age
9 @age
10 end
11 def age=(a)
12 @age = a
13 end
14 end
The Easy Way
1 class Person
2 attr_reader :name
3 attr_writer :social
4 attr_accessor :age
5 end
The Easy Way Explained
1 class Person
2 attr_reader :name
3 attr_writer :social
4 attr_accessor :age
5 end
• Ruby syntax allows method calls without ()
• Result is clean and looks like a language feature
• We can implement this ourselves
• Untested code, please do not copy:
1 class Object
2 def self.attr_reader(var)
3 class_eval <<-METHODS
4 def #{var}
5 @#{var}
6 end
7 METHODS
8 end
9 end
Why Blocks
1 (map (lambda (n)
2 (+ n 5))
3 ’(1 2 3))
4
Becomes:
1 [1,2,3].map do |n|
2 n + 5
3 end
Results in:
1 => [6,7,8]
1.3 Gems
Modules
1 module Voice
2 def say(msg)
3 puts msg
4 end
5 end
6
7 class Person
8 include Voice
9 end
10
11 p = Person.new
12 p.say(’Hello’) # prints ’Hello’
Using Gems
Require loads in files
1 require ’saver’ # pulls in ’saver.rb’
Gems allow us to not deal with paths
1 require ’rubygems’
2 require ’saver’
3
4 class Item
5 include Saver
6 end
Writing Gems
1 Gem::Specification.new do |s|
2 s.name = "saver"
3 s.version = Saver::VERSION
4 s.authors = ["Christopher Giroir"]
5 s.email = ["kelsin@valefor.com"]
6 s.homepage = "http://kelsin.github.com/saver/"
7
8 s.files = ‘git ls-files‘.split("n")
9 s.require_paths = ["lib"]
10
11 s.add_dependency ’activesupport’, ’~> 3.0.0’
12 s.add_dependency ’mongo_mapper’
13 end
5
2 Tools
2.1 Bundler
Why Bundler?
• Many projects (i.e. rails apps) are not gems themselves
• They do have gem dependencies
• Easy way to install and keep track of these dependencies
• Making sure ONLY the proper gems are used
The Gemfile
1 source ’http://tools1.savewave.com/rubygems’
2 source ’http://rubygems.org’
3
4 gem ’rails’, ’3.0.7’
5
6 gem ’sw-model’, ’0.13.0’
7
8 group :development, :test do
9 gem "rspec"
10 end
Using Bundler
1 # Install the gems from the Gemfile
2 bundle install
3
4 # Update gems to new versions
5 bundle update
6
7 # Execute command with proper gems
8 bundle exec rake spec
In your ruby code
1 require "rubygems"
2 require "bundler/setup"
3 require "saver"
Gemfile.lock
• When you initially install versions are saved to Gemfile.lock
• After they are only updated on bundle update
• SHOULD be checked into version control
• Protects from version updates
6
2.2 RVM
Why RVM?
• Different projects might use different versions of rails
• Different projects might use different ruby interpreters
– Ruby
– JRuby
– Rubinus
• While bundler helps, complete gem isolation is better!
• It’s nice to keep your system ruby separate and not update it
Using RVM
1 # Install the default 1.9.2 ruby interpretor
2 rvm install 1.9.2
3
4 # Switch to using 1.9.2
5 rvm use 1.9.2
6
7 # List installed rubies
8 rvm list
RVM Gemsets
1 # Create a new gemset
2 rvm gemset create savingstar-web
3
4 # List gemsets
5 rvm gemset list
6
7 # Switch to a ruby and gemset together
8 rvm use 1.9.2@savingstar-web
.rvmrc
• A .rvmrc file per project allows you to say which ruby and gemset to use
• Should be in source control. Helps RVM users out, ignored for others
• It’s a shell script that’s executed everytime you cd (very unsafe)
• Makes life very easy however!
1 rvm use 1.9.2@saveingstar-web --create
7

Más contenido relacionado

La actualidad más candente

20140419 oedo rubykaigi04
20140419 oedo rubykaigi0420140419 oedo rubykaigi04
20140419 oedo rubykaigi04
Hiroshi SHIBATA
 
20140425 ruby conftaiwan2014
20140425 ruby conftaiwan201420140425 ruby conftaiwan2014
20140425 ruby conftaiwan2014
Hiroshi SHIBATA
 
ApacheCon NA 2011 report
ApacheCon NA 2011 reportApacheCon NA 2011 report
ApacheCon NA 2011 report
Koji Kawamura
 

La actualidad más candente (16)

20140419 oedo rubykaigi04
20140419 oedo rubykaigi0420140419 oedo rubykaigi04
20140419 oedo rubykaigi04
 
20140425 ruby conftaiwan2014
20140425 ruby conftaiwan201420140425 ruby conftaiwan2014
20140425 ruby conftaiwan2014
 
An introduction and future of Ruby coverage library
An introduction and future of Ruby coverage libraryAn introduction and future of Ruby coverage library
An introduction and future of Ruby coverage library
 
How to distribute Ruby to the world
How to distribute Ruby to the worldHow to distribute Ruby to the world
How to distribute Ruby to the world
 
The Future of Bundled Bundler
The Future of Bundled BundlerThe Future of Bundled Bundler
The Future of Bundled Bundler
 
Rust Programming Language
Rust Programming LanguageRust Programming Language
Rust Programming Language
 
The Future of library dependency manageement of Ruby
The Future of library dependency manageement of RubyThe Future of library dependency manageement of Ruby
The Future of library dependency manageement of Ruby
 
ApacheCon NA 2011 report
ApacheCon NA 2011 reportApacheCon NA 2011 report
ApacheCon NA 2011 report
 
The Future of library dependency management of Ruby
 The Future of library dependency management of Ruby The Future of library dependency management of Ruby
The Future of library dependency management of Ruby
 
Multithread Your Application
Multithread Your ApplicationMultithread Your Application
Multithread Your Application
 
The Future of Dependency Management for Ruby
The Future of Dependency Management for RubyThe Future of Dependency Management for Ruby
The Future of Dependency Management for Ruby
 
Crystal
CrystalCrystal
Crystal
 
20140925 rails pacific
20140925 rails pacific20140925 rails pacific
20140925 rails pacific
 
Esoteric, Obfuscated, Artistic Programming in Ruby
Esoteric, Obfuscated, Artistic Programming in RubyEsoteric, Obfuscated, Artistic Programming in Ruby
Esoteric, Obfuscated, Artistic Programming in Ruby
 
My month with Ruby
My month with RubyMy month with Ruby
My month with Ruby
 
Ractor's speed is not light-speed
Ractor's speed is not light-speedRactor's speed is not light-speed
Ractor's speed is not light-speed
 

Similar a Ruby Presentation - Article

Charles nutter star techconf 2011 - jvm languages
Charles nutter   star techconf 2011 - jvm languagesCharles nutter   star techconf 2011 - jvm languages
Charles nutter star techconf 2011 - jvm languages
StarTech Conference
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
goccy
 

Similar a Ruby Presentation - Article (20)

Ruby Presentation - Handout
Ruby Presentation - HandoutRuby Presentation - Handout
Ruby Presentation - Handout
 
Ruby Presentation - Beamer
Ruby Presentation - BeamerRuby Presentation - Beamer
Ruby Presentation - Beamer
 
Perl 101
Perl 101Perl 101
Perl 101
 
Ruby Presentation
Ruby Presentation Ruby Presentation
Ruby Presentation
 
Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0
 
Charles nutter star techconf 2011 - jvm languages
Charles nutter   star techconf 2011 - jvm languagesCharles nutter   star techconf 2011 - jvm languages
Charles nutter star techconf 2011 - jvm languages
 
#CNX14 - Using Ruby for Reliability, Consistency, and Speed
#CNX14 - Using Ruby for Reliability, Consistency, and Speed#CNX14 - Using Ruby for Reliability, Consistency, and Speed
#CNX14 - Using Ruby for Reliability, Consistency, and Speed
 
Why Ruby?
Why Ruby? Why Ruby?
Why Ruby?
 
The details of CI/CD environment for Ruby
The details of CI/CD environment for RubyThe details of CI/CD environment for Ruby
The details of CI/CD environment for Ruby
 
How DSL works on Ruby
How DSL works on RubyHow DSL works on Ruby
How DSL works on Ruby
 
Testing your infallibleness
Testing your infalliblenessTesting your infallibleness
Testing your infallibleness
 
Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013
 
DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009
DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009
DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009
 
Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0
 
10 Things you should know about Ruby
10 Things you should know about Ruby10 Things you should know about Ruby
10 Things you should know about Ruby
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
rubyonrails
rubyonrailsrubyonrails
rubyonrails
 
rubyonrails
rubyonrailsrubyonrails
rubyonrails
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
 
11 Ruby Gems
11 Ruby Gems11 Ruby Gems
11 Ruby Gems
 

Último

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Ruby Presentation - Article

  • 1. Ruby: Why We Love It https://github.com/Kelsin/ruby-presentation Christopher Giroir November 8th, 2011 Contents 1 The Language 1 1.1 Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Why We Love It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.3 Gems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2 Tools 6 2.1 Bundler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.2 RVM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1 The Language 1.1 Basics Overview • Inspired by Smalltalk (which I love) • Also draws from Perl, Eiffel, Ada and LISP • Includes a REPL • Built for developers as a language they would love to use • Dynamic, strict, reflective, object oriented • Everything is an expression (even statements) • Everything is executed imperatively (even declarations) Object Oriented • Everything is an object • Single Inheritance • Modules can be mixed in • Dynamic Dispatch 1
  • 2. Simple Code 1 5.times { print "Hello" } This outputs: 1 Hello 2 Hello 3 Hello 4 Hello 5 Hello 6 => 5 Types 1 # Strings 2 s = ’Testing’ 3 4 # Interpreted Strings 5 t = "Double #{str}" 6 7 # Symbols 8 sym = :chris 9 10 # Arrays 11 a = [1,2,3] 12 13 # Hashes 14 h = { :key => ’value’, :chris => ’awesome’ } Classes 1 class Box 2 def initialize(w,h,d) 3 @width = w 4 @height = h 5 @depth = d 6 end 7 8 def volume 9 @width * @height * @depth 10 end 11 end 12 13 box = Box.new(2,2,2) 14 box.volume # => 8 Simple Inheritance 1 class JackInTheBox < Box 2 def initialize(msg) 3 @msg = msg 2
  • 3. 4 super(3,3,3) 5 end 6 7 def open 8 puts @msg 9 end 10 end 11 12 jbox = JackInTheBox.new(’Surprise!’) 13 jbox.volume # => 27 14 jbox.open # prints ’Surprise!’ Control 1 while true == false 2 if var == 5 3 break 4 end 5 6 begin 7 var - 1 8 end while var < 4 9 10 next if var == 6 11 end Blocks 1 [1,2,3].each { |n| puts n } This outputs: 1 1 2 2 3 3 4 => [1,2,3] Block Syntax 1 5.upto(10) { |n| puts n } This is exactly the same as the following: 1 5.upto(10) do |n| 2 puts n 3 end 1.2 Why We Love It Attribute Methods 3
  • 4. 1 class Person 2 def name 3 @name 4 end 5 def social=(s) 6 @social = s 7 end 8 def age 9 @age 10 end 11 def age=(a) 12 @age = a 13 end 14 end The Easy Way 1 class Person 2 attr_reader :name 3 attr_writer :social 4 attr_accessor :age 5 end The Easy Way Explained 1 class Person 2 attr_reader :name 3 attr_writer :social 4 attr_accessor :age 5 end • Ruby syntax allows method calls without () • Result is clean and looks like a language feature • We can implement this ourselves • Untested code, please do not copy: 1 class Object 2 def self.attr_reader(var) 3 class_eval <<-METHODS 4 def #{var} 5 @#{var} 6 end 7 METHODS 8 end 9 end Why Blocks 1 (map (lambda (n) 2 (+ n 5)) 3 ’(1 2 3)) 4
  • 5. Becomes: 1 [1,2,3].map do |n| 2 n + 5 3 end Results in: 1 => [6,7,8] 1.3 Gems Modules 1 module Voice 2 def say(msg) 3 puts msg 4 end 5 end 6 7 class Person 8 include Voice 9 end 10 11 p = Person.new 12 p.say(’Hello’) # prints ’Hello’ Using Gems Require loads in files 1 require ’saver’ # pulls in ’saver.rb’ Gems allow us to not deal with paths 1 require ’rubygems’ 2 require ’saver’ 3 4 class Item 5 include Saver 6 end Writing Gems 1 Gem::Specification.new do |s| 2 s.name = "saver" 3 s.version = Saver::VERSION 4 s.authors = ["Christopher Giroir"] 5 s.email = ["kelsin@valefor.com"] 6 s.homepage = "http://kelsin.github.com/saver/" 7 8 s.files = ‘git ls-files‘.split("n") 9 s.require_paths = ["lib"] 10 11 s.add_dependency ’activesupport’, ’~> 3.0.0’ 12 s.add_dependency ’mongo_mapper’ 13 end 5
  • 6. 2 Tools 2.1 Bundler Why Bundler? • Many projects (i.e. rails apps) are not gems themselves • They do have gem dependencies • Easy way to install and keep track of these dependencies • Making sure ONLY the proper gems are used The Gemfile 1 source ’http://tools1.savewave.com/rubygems’ 2 source ’http://rubygems.org’ 3 4 gem ’rails’, ’3.0.7’ 5 6 gem ’sw-model’, ’0.13.0’ 7 8 group :development, :test do 9 gem "rspec" 10 end Using Bundler 1 # Install the gems from the Gemfile 2 bundle install 3 4 # Update gems to new versions 5 bundle update 6 7 # Execute command with proper gems 8 bundle exec rake spec In your ruby code 1 require "rubygems" 2 require "bundler/setup" 3 require "saver" Gemfile.lock • When you initially install versions are saved to Gemfile.lock • After they are only updated on bundle update • SHOULD be checked into version control • Protects from version updates 6
  • 7. 2.2 RVM Why RVM? • Different projects might use different versions of rails • Different projects might use different ruby interpreters – Ruby – JRuby – Rubinus • While bundler helps, complete gem isolation is better! • It’s nice to keep your system ruby separate and not update it Using RVM 1 # Install the default 1.9.2 ruby interpretor 2 rvm install 1.9.2 3 4 # Switch to using 1.9.2 5 rvm use 1.9.2 6 7 # List installed rubies 8 rvm list RVM Gemsets 1 # Create a new gemset 2 rvm gemset create savingstar-web 3 4 # List gemsets 5 rvm gemset list 6 7 # Switch to a ruby and gemset together 8 rvm use 1.9.2@savingstar-web .rvmrc • A .rvmrc file per project allows you to say which ruby and gemset to use • Should be in source control. Helps RVM users out, ignored for others • It’s a shell script that’s executed everytime you cd (very unsafe) • Makes life very easy however! 1 rvm use 1.9.2@saveingstar-web --create 7