SlideShare a Scribd company logo
Ruby Programmers’ Best Friend Jason Morrison January 19, 2006 Rochester on Rails
History
Ruby Yukihiro “Matz” Matsumoto February 24, 1993
Perl  Java  Python  Ruby   PHP 1987  1991  1993   1995
Examples!
5.times { print “Ruby! " }
Ruby! Ruby! Ruby! Ruby! Ruby! 5.times { print “Ruby! " }
[‘one’,‘two’,‘three’].each {|num| puts num.capitalize }
[‘one’,‘two’,‘three’].each {|num| puts num.capitalize }  One Two Three
Everything is an object
-21474836480.abs
-21474836480.abs 21474836480
“ Rats live on no evil star”   .reverse.capitalize
“ Rats live on no evil star”   .reverse.capitalize “ Rats live on no evil star”
3.hours.from_now
3.hours.from_now Thu Jan 19 22:05:00 Eastern    Standard Time 2006
Conventions
Variables colored_index_cards
Class Names DromedaryDiner
Symbols :creme_de_menthe
Instance Variables @euros_per_liter
Constants Kilograms_Per_Pound
Syntax
Methods def say_hello(name)   result = “Hello, #{name}!”   return result end puts say_hello(“world”)
Methods def say_hello(name)   “Hello, #{name}!” end puts say_hello(“world”)
Classes class MathWhiz def say_square(value)   puts value * value end end sam = MathWhiz.new sam.say_square(5)
Open Classes class Integer def squared self * self end end 5.squared  #=> 25
Inheritance class Whopper < Burger @maker = “Burger King” @calories = 0.67 * 10**3 end
Class Methods class FileUtil def self.mkdir(dir) # do it!   end end FileUtil.mkdir(“oranges”)
Modules module Trig PI = 3.141592654 def Trig.sin(x) # .. end def Trig.cos(x) # .. end end
Modules require &quot;trig&quot; y = Trig.sin(Trig::PI/4) 0.707106780551956
Mixins module Debug def whoAmI? “ #{self.type.name} ” + “ (\##{self.id}): ” + “ #{self.to_s}&quot; end end
Mixins class Phonograph include Debug # ... end ph = Phonograph.new(&quot;West End Blues&quot;) ph.whoAmI? &quot;Phonograph (#537766170): West End Blues&quot;
Attributes class PlainOldRubyObject attr_accessor :food, :drinks attr_reader  :advice attr_writer  :write_only end
Scope class Poet #public by default def poetry end protected def family_legacy end private def hopes_and_dreams end end
Arrays
foo = [] foo << 1  #=> [1] foo << 2  #=> [1, 2] foo << 3  #=> [1, 2, 3]
bar = [1, 2, 3] bar << 4  #=> [1, 2, 3, 4] bar << 5  #=> [1, 2, 3, 4, 5] bar << 6  #=> [1, 2, 3, 4, 5, 6]
folks = %w( Charles Ed Amanda ) #=> [“Charles”, “Ed”, “Amanda”] folks[1] Ed
Hashes
menu = { :douglas_sirk_steak  => 17.50, :vanilla_coke  => 2.75, :durwood_kirby_burger => 9.75, :five_dollar_shake  => 5.00 } menu[:vanilla_coke] 2.75
Flow
if ( score >= 5000 ) puts “You win!” elsif ( score <= 0 ) puts “Game over.” else puts “Current score: #{score}” end
puts “Watch out!” if lion_distance < 5
Blocks
1.upto(5) { |x| puts x } 1 2 3 4 5
5.downto(1) do |time| print “#{time}... ” puts “!” if time <= 3 end 5... 4... 3... ! 2... ! 1... !
Fín!
Homepage www.ruby-lang.org Try Ruby in your browser tryruby.hobix.com  Ruby with humor   www.poignantguide.net

More Related Content

PPT
eJADA web development the Ruby way
PDF
Beware sharp tools
PDF
Crystal: Fundamentos, objetivos y desafios - Cacic 2019
PPT
PERL Unit 6 regular expression
PPT
Introduction to Ruby, Rails, and Ruby on Rails
PDF
Catch and Throw in Ruby
DOCX
Manga recome (indonesai)
PDF
Hacker 101/102 - Introduction to Programming w/Processing
eJADA web development the Ruby way
Beware sharp tools
Crystal: Fundamentos, objetivos y desafios - Cacic 2019
PERL Unit 6 regular expression
Introduction to Ruby, Rails, and Ruby on Rails
Catch and Throw in Ruby
Manga recome (indonesai)
Hacker 101/102 - Introduction to Programming w/Processing

What's hot (10)

PPTX
Scripting 101
PDF
Ruby.new @ VilniusRB
PDF
Vim Hacks
KEY
Raspagem da dados com Hpricot e Sinatra
PPT
La Corrida
PPT
La Corrida
PPT
La Corrida
PPT
La Corrida
PDF
Ruby - Uma Introdução
PDF
Ruby and japanese
Scripting 101
Ruby.new @ VilniusRB
Vim Hacks
Raspagem da dados com Hpricot e Sinatra
La Corrida
La Corrida
La Corrida
La Corrida
Ruby - Uma Introdução
Ruby and japanese
Ad

Viewers also liked (10)

PPT
Rochester on Rails: Introduction to Rails
PPT
Rockit: A Parser Generator for Ruby
PDF
Clearance: Simple, complete Ruby web app authentication.
KEY
SmartLab at Ignite Boston 5
PDF
Writing DSLs with Parslet - Wicked Good Ruby Conf
PPTX
Matthew Nixon, Coca Cola Amatil
PDF
Synthetic Biology at BarcampRochester3
PPTX
Role of Operators in the Mobile App Delivery Ecosystem
PPT
Multitouch: FTIR
PPTX
The World's Best Mobile App Developers 2012
Rochester on Rails: Introduction to Rails
Rockit: A Parser Generator for Ruby
Clearance: Simple, complete Ruby web app authentication.
SmartLab at Ignite Boston 5
Writing DSLs with Parslet - Wicked Good Ruby Conf
Matthew Nixon, Coca Cola Amatil
Synthetic Biology at BarcampRochester3
Role of Operators in the Mobile App Delivery Ecosystem
Multitouch: FTIR
The World's Best Mobile App Developers 2012
Ad

Similar to Rochester on Rails: Introduction to Ruby (20)

PDF
Rapid Development with Ruby/JRuby and Rails
PDF
Introduction to Ruby Programming Language
PPT
name name2 n2.ppt
PPT
name name2 n
PPT
name name2 n2
PPT
name name2 n
PPT
ppt18
PPT
ppt9
PPT
ppt7
PPT
ppt30
PPT
ppt21
PPT
ppt2
PPT
ppt17
PPT
Ruby for Perl Programmers
PPT
name name2 n
PPT
test ppt
PDF
Ruby presentasjon på NTNU 22 april 2009
PDF
Ruby presentasjon på NTNU 22 april 2009
PDF
Ruby presentasjon på NTNU 22 april 2009
PDF
Ruby 程式語言簡介
Rapid Development with Ruby/JRuby and Rails
Introduction to Ruby Programming Language
name name2 n2.ppt
name name2 n
name name2 n2
name name2 n
ppt18
ppt9
ppt7
ppt30
ppt21
ppt2
ppt17
Ruby for Perl Programmers
name name2 n
test ppt
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
Ruby 程式語言簡介

Recently uploaded (20)

PDF
BsN 7th Sem Course GridNNNNNNNN CCN.pdf
PPTX
Lecture (1)-Introduction.pptx business communication
PDF
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
PPTX
HR Introduction Slide (1).pptx on hr intro
PDF
Types of control:Qualitative vs Quantitative
PPTX
New Microsoft PowerPoint Presentation - Copy.pptx
PDF
COST SHEET- Tender and Quotation unit 2.pdf
PDF
Ôn tập tiếng anh trong kinh doanh nâng cao
PDF
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
PPTX
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh
PDF
20250805_A. Stotz All Weather Strategy - Performance review July 2025.pdf
PPTX
The Marketing Journey - Tracey Phillips - Marketing Matters 7-2025.pptx
PDF
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
PDF
Laughter Yoga Basic Learning Workshop Manual
PDF
MSPs in 10 Words - Created by US MSP Network
PPTX
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx
PPTX
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
PDF
IFRS Notes in your pocket for study all the time
PDF
Chapter 5_Foreign Exchange Market in .pdf
PPTX
Belch_12e_PPT_Ch18_Accessible_university.pptx
BsN 7th Sem Course GridNNNNNNNN CCN.pdf
Lecture (1)-Introduction.pptx business communication
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
HR Introduction Slide (1).pptx on hr intro
Types of control:Qualitative vs Quantitative
New Microsoft PowerPoint Presentation - Copy.pptx
COST SHEET- Tender and Quotation unit 2.pdf
Ôn tập tiếng anh trong kinh doanh nâng cao
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh
20250805_A. Stotz All Weather Strategy - Performance review July 2025.pdf
The Marketing Journey - Tracey Phillips - Marketing Matters 7-2025.pptx
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
Laughter Yoga Basic Learning Workshop Manual
MSPs in 10 Words - Created by US MSP Network
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
IFRS Notes in your pocket for study all the time
Chapter 5_Foreign Exchange Market in .pdf
Belch_12e_PPT_Ch18_Accessible_university.pptx

Rochester on Rails: Introduction to Ruby