SlideShare a Scribd company logo
Learn Ruby 2011
     Session 3
Our Sponsors
Flatsourcing, iSeatz, Koda, and Launchpad
Language Crashing
  Learning the basics in pieces
Questions
Having any problems? Discover anything cool?
Arrays


• An Array is an ordered list of values
• Arrays in Ruby are zero-indexed
Arrays
array = [“One”,”Two”,”Three”]
puts array[0]
One
array.each { |v| puts v }
One
Two
Three
Hashes


• Hashes are unordered lists of values
• Hashes are indexed using “keys” which can
  being either strings or symbols
Hashes

hash = {‘one’ => “One”, :two => ”Two”}
puts hash[‘one’]
One
puts hash[:two]
Three
Symbols

• Symbols are essentially constants that don’t
  need to be declared ahead of time
• A Symbol has a simple string-like
  representation and is guaranteed to have a
  unique value
Symbols

def walk(direction)
  if direction == :north
    # ...
  end
end
Symbols

• Symbols are most commonly found as the
  keys for hashes
• They are slightly more memory efficient than
  using strings for the same purposes
Control Structures

• Control structures allow you to handle
  conditional behaviors
• Control structures allow you to handle
  iterations/loops
Control Structures
• if ... else ... elsif
• while
• case ... when
• for ... in
• until
• unless
Control Structures

if i == 3
  # ...
elsif i == 4
  # ...
else
  # ...
end
Control Structures


unless i == 3
  # ...
end
Control Structures


while i < 3
  # ...
end
Control Structures


until i < 3
  # ...
end
Control Structures

case i
  when 3
    # ...
  when 4
    # ...
  else
    # ...
end
Control Structures

for i in 1..3
  # ...
end

for i in [‘one’,‘two’,‘three’]
  # ...
end
Regular Expressions

• Regular Expressions are used for text parsing
  and manipulation
• They can represent a sort of programming
  language unto themselves
Blocks

• Sections of code that can be passed to
  methods like parameters
• Represented as code within curly braces or
  between do and end
Blocks
def call_block
  puts "Start of method"
  yield
  puts "End of method"
end

call_block { puts "In the block" }
Start of method
In the block
End of method
Iterators


• A type of code block that works with
  successive values of some collection
• Used extensively for arrays and hashes
Iterators

[‘One’,‘Two’,‘Three’].each do |val|
  puts val
end
One
Two
Three
Reviewing

• Arrays & Hashes
• Symbols
• Control Structures
• Regular Expressions
• Blocks & Iterators
For Next Week
For the New to Programming

•   Read Chapters 5, 6, 7 & 8 in LtP
•   Complete exercises for each chapter
For Everyone

•   Read Chapter 2, 7 & 9 in PR1.9
•   Work on the Ruby Koans at a leisurely
    pace
Next Week


• Deeper into Classes & Variables
Exercises

• Visit http://rubykoans.com/ & Download
• Begin working through the Koans by
    running `ruby path_to_enlightenment.rb`
•

More Related Content

What's hot (20)

PDF
Value Objects
Dhaval Dalal
 
KEY
Introducing Ruby
James Thompson
 
ODP
Ruby
Aizat Faiz
 
PDF
Ruby Metaprogramming - OSCON 2008
Brian Sam-Bodden
 
PPT
Ruby For Java Programmers
Mike Bowler
 
PPTX
Episode 8 - Path To Code - Integrate Salesforce with external system using R...
Jitendra Zaa
 
ODP
Intro Ruby Classes Part I
Juan Leal
 
PDF
Javascript for Intermediates
Ankit Agrawal
 
PPTX
Metaprogramming in Ruby
Volodymyr Byno
 
PDF
Scala days mizushima
Skills Matter Talks
 
ODP
Constructors, Intro to Ruby Classes Part II
Juan Leal
 
PDF
Introduction to Ruby
kim.mens
 
PPTX
Scala - the good, the bad and the very ugly
Bozhidar Bozhanov
 
PDF
Ruby Presentation
platico_dev
 
PPTX
Children of Ruby
Simon St.Laurent
 
PDF
Scala the-good-parts
Fuqiang Wang
 
PDF
WDB005.1 - JavaScript for Java Developers (Lecture 1)
Igor Khotin
 
PDF
Ruby Programming Introduction
Anthony Brown
 
PPTX
OOPs fundamentals session for freshers in my office (Aug 5, 13)
Ashoka R K T
 
PDF
PureScript Tutorial 1
Ray Shih
 
Value Objects
Dhaval Dalal
 
Introducing Ruby
James Thompson
 
Ruby Metaprogramming - OSCON 2008
Brian Sam-Bodden
 
Ruby For Java Programmers
Mike Bowler
 
Episode 8 - Path To Code - Integrate Salesforce with external system using R...
Jitendra Zaa
 
Intro Ruby Classes Part I
Juan Leal
 
Javascript for Intermediates
Ankit Agrawal
 
Metaprogramming in Ruby
Volodymyr Byno
 
Scala days mizushima
Skills Matter Talks
 
Constructors, Intro to Ruby Classes Part II
Juan Leal
 
Introduction to Ruby
kim.mens
 
Scala - the good, the bad and the very ugly
Bozhidar Bozhanov
 
Ruby Presentation
platico_dev
 
Children of Ruby
Simon St.Laurent
 
Scala the-good-parts
Fuqiang Wang
 
WDB005.1 - JavaScript for Java Developers (Lecture 1)
Igor Khotin
 
Ruby Programming Introduction
Anthony Brown
 
OOPs fundamentals session for freshers in my office (Aug 5, 13)
Ashoka R K T
 
PureScript Tutorial 1
Ray Shih
 

Viewers also liked (20)

KEY
Ruby For Web Development
James Thompson
 
PPTX
Creating powerful resumes
Edventures1 Learning Solutions
 
KEY
Learn Ruby 2011 - Session 4 - Objects, Oh My!
James Thompson
 
PPTX
Ects 504, wr icebreaker
Resort Opportunities(tm)
 
PPS
Thoughts
guest6067361
 
PPS
Meilleures Photos De Time Magazine
tanhadk
 
PPTX
MP2 - 10 Minutes to Domain Success
Resort Opportunities(tm)
 
PDF
Shinesquad Services Cards Summer 2012
Shinesquad
 
PDF
Igniting ambitions
Edventures1 Learning Solutions
 
PDF
Altar Cards
Maurice R. TREMBLAY
 
PPTX
Mss Presentation 2009 Master
gordy1976
 
PDF
Turkey -Tax And Social Security Legislation Annual Update 2011
Shinesquad
 
PPS
Moments
guest6067361
 
PDF
Ganadores Proyectos de Modding CPCO5
Juan Sebastian Campos Zapata
 
PDF
PART II.2 - Modern Physics
Maurice R. TREMBLAY
 
DOC
Networking
Resty Shane Amora
 
PPTX
MglausCom Meeting Pictures 25112012
Gegeen Australia
 
PDF
Cgpkcin2014conf 160416035350
Safucon
 
PPTX
Skills to win_in_interviews
Edventures1 Learning Solutions
 
Ruby For Web Development
James Thompson
 
Creating powerful resumes
Edventures1 Learning Solutions
 
Learn Ruby 2011 - Session 4 - Objects, Oh My!
James Thompson
 
Ects 504, wr icebreaker
Resort Opportunities(tm)
 
Thoughts
guest6067361
 
Meilleures Photos De Time Magazine
tanhadk
 
MP2 - 10 Minutes to Domain Success
Resort Opportunities(tm)
 
Shinesquad Services Cards Summer 2012
Shinesquad
 
Igniting ambitions
Edventures1 Learning Solutions
 
Altar Cards
Maurice R. TREMBLAY
 
Mss Presentation 2009 Master
gordy1976
 
Turkey -Tax And Social Security Legislation Annual Update 2011
Shinesquad
 
Moments
guest6067361
 
Ganadores Proyectos de Modding CPCO5
Juan Sebastian Campos Zapata
 
PART II.2 - Modern Physics
Maurice R. TREMBLAY
 
Networking
Resty Shane Amora
 
MglausCom Meeting Pictures 25112012
Gegeen Australia
 
Cgpkcin2014conf 160416035350
Safucon
 
Skills to win_in_interviews
Edventures1 Learning Solutions
 
Ad

Similar to Learn Ruby 2011 - Session 3 (20)

PDF
Blocks and loops.pptx
sandeep kumar
 
PPTX
Ruby data types and objects
Harkamal Singh
 
PPTX
Ruby basics ||
datt30
 
PPTX
Ruby from zero to hero
Diego Lemos
 
PDF
Ruby — An introduction
Gonçalo Silva
 
PPTX
Ruby basics
Tushar Pal
 
PPT
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
PPT
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
PDF
Introduction to Ruby Programming Language
Nicolò Calcavecchia
 
PPTX
Ruby -the wheel Technology
ppparthpatel123
 
PDF
Ruby 101 && Coding Dojo
Guilherme
 
PPTX
Ruby Basics
NagaLakshmi_N
 
KEY
Learn Ruby 2011 - Session 5 - Looking for a Rescue
James Thompson
 
PDF
Ruby training day1
Bindesh Vijayan
 
ODP
Ruby Basics by Rafiq
Rafiqdeen
 
PPTX
Ruby introduction part1
Brady Cheng
 
PDF
Ruby_Basic
Kushal Jangid
 
PDF
Ruby an overall approach
Felipe Schmitt
 
PPTX
Code for Startup MVP (Ruby on Rails) Session 2
Henry S
 
Blocks and loops.pptx
sandeep kumar
 
Ruby data types and objects
Harkamal Singh
 
Ruby basics ||
datt30
 
Ruby from zero to hero
Diego Lemos
 
Ruby — An introduction
Gonçalo Silva
 
Ruby basics
Tushar Pal
 
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
Introduction to Ruby Programming Language
Nicolò Calcavecchia
 
Ruby -the wheel Technology
ppparthpatel123
 
Ruby 101 && Coding Dojo
Guilherme
 
Ruby Basics
NagaLakshmi_N
 
Learn Ruby 2011 - Session 5 - Looking for a Rescue
James Thompson
 
Ruby training day1
Bindesh Vijayan
 
Ruby Basics by Rafiq
Rafiqdeen
 
Ruby introduction part1
Brady Cheng
 
Ruby_Basic
Kushal Jangid
 
Ruby an overall approach
Felipe Schmitt
 
Code for Startup MVP (Ruby on Rails) Session 2
Henry S
 
Ad

More from James Thompson (9)

PPTX
Interfaces Not Required — RubyHACK 2018
James Thompson
 
PDF
Bounded Contexts for Legacy Code
James Thompson
 
PDF
Beyond Accidental Arcitecture
James Thompson
 
PDF
Effective Pair Programming
James Thompson
 
PPTX
Wrapping an api with a ruby gem
James Thompson
 
PPTX
Microservices for the Monolith
James Thompson
 
PDF
Mocking & Stubbing
James Thompson
 
KEY
Rails: Scaling Edition - Getting on Rails 3
James Thompson
 
KEY
Ruby Testing: Cucumber and RSpec
James Thompson
 
Interfaces Not Required — RubyHACK 2018
James Thompson
 
Bounded Contexts for Legacy Code
James Thompson
 
Beyond Accidental Arcitecture
James Thompson
 
Effective Pair Programming
James Thompson
 
Wrapping an api with a ruby gem
James Thompson
 
Microservices for the Monolith
James Thompson
 
Mocking & Stubbing
James Thompson
 
Rails: Scaling Edition - Getting on Rails 3
James Thompson
 
Ruby Testing: Cucumber and RSpec
James Thompson
 

Recently uploaded (20)

PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
July Patch Tuesday
Ivanti
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 

Learn Ruby 2011 - Session 3

Editor's Notes