SlideShare une entreprise Scribd logo
1  sur  28
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`
•

Contenu connexe

Tendances

Tendances (20)

Value Objects
Value ObjectsValue Objects
Value Objects
 
Introducing Ruby
Introducing RubyIntroducing Ruby
Introducing Ruby
 
Ruby
RubyRuby
Ruby
 
Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008
 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java Programmers
 
Episode 8 - Path To Code - Integrate Salesforce with external system using R...
Episode 8  - Path To Code - Integrate Salesforce with external system using R...Episode 8  - Path To Code - Integrate Salesforce with external system using R...
Episode 8 - Path To Code - Integrate Salesforce with external system using R...
 
Intro Ruby Classes Part I
Intro Ruby Classes Part IIntro Ruby Classes Part I
Intro Ruby Classes Part I
 
Javascript for Intermediates
Javascript for IntermediatesJavascript for Intermediates
Javascript for Intermediates
 
Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Ruby
 
Scala days mizushima
Scala days mizushimaScala days mizushima
Scala days mizushima
 
Constructors, Intro to Ruby Classes Part II
Constructors, Intro to Ruby Classes Part IIConstructors, Intro to Ruby Classes Part II
Constructors, Intro to Ruby Classes Part II
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very ugly
 
Ruby Presentation
Ruby Presentation Ruby Presentation
Ruby Presentation
 
Children of Ruby
Children of RubyChildren of Ruby
Children of Ruby
 
Scala the-good-parts
Scala the-good-partsScala the-good-parts
Scala the-good-parts
 
WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)
 
Ruby Programming Introduction
Ruby Programming IntroductionRuby Programming Introduction
Ruby Programming Introduction
 
OOPs fundamentals session for freshers in my office (Aug 5, 13)
OOPs fundamentals session for freshers in my office (Aug 5, 13)OOPs fundamentals session for freshers in my office (Aug 5, 13)
OOPs fundamentals session for freshers in my office (Aug 5, 13)
 
PureScript Tutorial 1
PureScript Tutorial 1PureScript Tutorial 1
PureScript Tutorial 1
 

En vedette

Meilleures Photos De Time Magazine
Meilleures Photos De Time MagazineMeilleures Photos De Time Magazine
Meilleures Photos De Time Magazine
tanhadk
 
Mss Presentation 2009 Master
Mss Presentation 2009 MasterMss Presentation 2009 Master
Mss Presentation 2009 Master
gordy1976
 
MglausCom Meeting Pictures 25112012
MglausCom Meeting Pictures 25112012MglausCom Meeting Pictures 25112012
MglausCom Meeting Pictures 25112012
Gegeen Australia
 

En vedette (20)

Ruby For Web Development
Ruby For Web DevelopmentRuby For Web Development
Ruby For Web Development
 
Creating powerful resumes
Creating powerful resumesCreating powerful resumes
Creating powerful resumes
 
Learn Ruby 2011 - Session 4 - Objects, Oh My!
Learn Ruby 2011 - Session 4 - Objects, Oh My!Learn Ruby 2011 - Session 4 - Objects, Oh My!
Learn Ruby 2011 - Session 4 - Objects, Oh My!
 
Ects 504, wr icebreaker
Ects 504, wr  icebreakerEcts 504, wr  icebreaker
Ects 504, wr icebreaker
 
Thoughts
ThoughtsThoughts
Thoughts
 
Meilleures Photos De Time Magazine
Meilleures Photos De Time MagazineMeilleures Photos De Time Magazine
Meilleures Photos De Time Magazine
 
Creatvity
CreatvityCreatvity
Creatvity
 
MP2 - 10 Minutes to Domain Success
MP2 - 10 Minutes to Domain SuccessMP2 - 10 Minutes to Domain Success
MP2 - 10 Minutes to Domain Success
 
Shinesquad Services Cards Summer 2012
Shinesquad Services Cards Summer 2012Shinesquad Services Cards Summer 2012
Shinesquad Services Cards Summer 2012
 
Igniting ambitions
Igniting ambitionsIgniting ambitions
Igniting ambitions
 
Altar Cards
Altar CardsAltar Cards
Altar Cards
 
Mss Presentation 2009 Master
Mss Presentation 2009 MasterMss Presentation 2009 Master
Mss Presentation 2009 Master
 
Turkey -Tax And Social Security Legislation Annual Update 2011
Turkey -Tax And Social Security Legislation Annual Update 2011Turkey -Tax And Social Security Legislation Annual Update 2011
Turkey -Tax And Social Security Legislation Annual Update 2011
 
Moments
MomentsMoments
Moments
 
Ganadores Proyectos de Modding CPCO5
Ganadores Proyectos de Modding CPCO5Ganadores Proyectos de Modding CPCO5
Ganadores Proyectos de Modding CPCO5
 
PART II.2 - Modern Physics
PART II.2 - Modern PhysicsPART II.2 - Modern Physics
PART II.2 - Modern Physics
 
Networking
NetworkingNetworking
Networking
 
MglausCom Meeting Pictures 25112012
MglausCom Meeting Pictures 25112012MglausCom Meeting Pictures 25112012
MglausCom Meeting Pictures 25112012
 
Cgpkcin2014conf 160416035350
Cgpkcin2014conf 160416035350Cgpkcin2014conf 160416035350
Cgpkcin2014conf 160416035350
 
Skills to win_in_interviews
Skills to win_in_interviewsSkills to win_in_interviews
Skills to win_in_interviews
 

Similaire à Learn Ruby 2011 - Session 3

Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
Edureka!
 

Similaire à Learn Ruby 2011 - Session 3 (20)

Ruby basics
Ruby basicsRuby basics
Ruby basics
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2
 
Getting started in Python presentation by Laban K
Getting started in Python presentation by Laban KGetting started in Python presentation by Laban K
Getting started in Python presentation by Laban K
 
Python first day
Python first dayPython first day
Python first day
 
Python first day
Python first dayPython first day
Python first day
 
Java
JavaJava
Java
 
4 Expressions and Operators
4  Expressions and Operators4  Expressions and Operators
4 Expressions and Operators
 
Python assignment help
Python assignment helpPython assignment help
Python assignment help
 
Php classes in mumbai
Php classes in mumbaiPhp classes in mumbai
Php classes in mumbai
 
Intro to Perl
Intro to PerlIntro to Perl
Intro to Perl
 
Mit6 094 iap10_lec01
Mit6 094 iap10_lec01Mit6 094 iap10_lec01
Mit6 094 iap10_lec01
 
PHP - Introduction to PHP
PHP -  Introduction to PHPPHP -  Introduction to PHP
PHP - Introduction to PHP
 
Javascript
JavascriptJavascript
Javascript
 
Apex code (Salesforce)
Apex code (Salesforce)Apex code (Salesforce)
Apex code (Salesforce)
 
Matlab lec1
Matlab lec1Matlab lec1
Matlab lec1
 
DIG1108C Lesson 5 Fall 2014
DIG1108C Lesson 5 Fall 2014DIG1108C Lesson 5 Fall 2014
DIG1108C Lesson 5 Fall 2014
 
Lecture_4.pdf
Lecture_4.pdfLecture_4.pdf
Lecture_4.pdf
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 

Plus de James Thompson

Wrapping an api with a ruby gem
Wrapping an api with a ruby gemWrapping an api with a ruby gem
Wrapping an api with a ruby gem
James Thompson
 

Plus de James Thompson (10)

Interfaces Not Required — RubyHACK 2018
Interfaces Not Required — RubyHACK 2018Interfaces Not Required — RubyHACK 2018
Interfaces Not Required — RubyHACK 2018
 
Bounded Contexts for Legacy Code
Bounded Contexts for Legacy CodeBounded Contexts for Legacy Code
Bounded Contexts for Legacy Code
 
Beyond Accidental Arcitecture
Beyond Accidental ArcitectureBeyond Accidental Arcitecture
Beyond Accidental Arcitecture
 
Effective Pair Programming
Effective Pair ProgrammingEffective Pair Programming
Effective Pair Programming
 
Wrapping an api with a ruby gem
Wrapping an api with a ruby gemWrapping an api with a ruby gem
Wrapping an api with a ruby gem
 
Microservices for the Monolith
Microservices for the MonolithMicroservices for the Monolith
Microservices for the Monolith
 
Mocking & Stubbing
Mocking & StubbingMocking & Stubbing
Mocking & Stubbing
 
Learn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a RescueLearn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a Rescue
 
Rails: Scaling Edition - Getting on Rails 3
Rails: Scaling Edition - Getting on Rails 3Rails: Scaling Edition - Getting on Rails 3
Rails: Scaling Edition - Getting on Rails 3
 
Ruby Testing: Cucumber and RSpec
Ruby Testing: Cucumber and RSpecRuby Testing: Cucumber and RSpec
Ruby Testing: Cucumber and RSpec
 

Dernier

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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
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
 
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
 
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
 
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 ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
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)
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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
 
"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 ...
 
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
 

Learn Ruby 2011 - Session 3

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n