SlideShare a Scribd company logo
1 of 35
Learn Ruby 2011
     Session 2
Our Sponsors
Flatsourcing, iSeatz, Koda, and Launchpad
Welcome Back
 Ready to learn some Ruby?
Our Books
Learn to Program, 2ed

•   For total beginners

•   Systematic coverage of
    programming concepts

•   Uses Ruby to teach
    programming
Programming Ruby, 3ed

•   Comprehensive langauge
    reference

•   Covers Ruby 1.9.2,
    annotations for 1.9 and
    1.9.2 specific features

•   de facto standard
    reference
Language Crashing
  Learning the basics in pieces
Objects vs Classes

• An Object is a discreet thing
• You can do things to Objects
• Classes tell you how to build Objects
• Classes in Ruby are also Objects
Objects vs Classes
• A Car is a Class
• My Car is an Object
• My Car has lots of things in common with
  other cars
• So, My Car is a Car
• But, Not every Car is My Car
Everything is an Object


• In Ruby everything is an object
• This means you can do things to everything
  you come across.
Everything has a Class

• Because everything is an Object, everything
  also has a class
• An Object’s class is often referred to as it’s
  Type
Duck Typing

• Ruby is Duck Typed
• This means that when you encounter an
  Object in Ruby, what you can do to it
  determines it’s type
• Ruby’s “Type Model” is concerned with
  what you can do with Objects
A Sample of Ruby

def say_goodnight(name)
  result = “Good night, “ + name
  return result
end
puts say_goodnight(“John-Boy”)
puts say_goodnight(“Mary-Ellen”)
Variables

def say_goodnight(name)
  result = “Good night, “ + name
  return result
end
puts say_goodnight(“John-Boy”)
puts say_goodnight(“Mary-Ellen”)
Variables

• Variables hold values, in Ruby they hold
  Objects
• Variables are the handles we use to easily
  reference the data we want to work with
Variables

• There are four basic kinds of variables
 • local_variables
 • @instance_variables
 • @@class_variables
 • $global_variables
Variables

• There are also Constants, variables that
  don’t change
  • ClassNames
  • CONSTANT_NAME
Variables

def say_goodnight(name)
  result = “Good night, “ + name
  return result
end
puts say_goodnight(“John-Boy”)
puts say_goodnight(“Mary-Ellen”)
Strings

def say_goodnight(name)
  result = “Good night, “ + name
  return result
end
puts say_goodnight(“John-Boy”)
puts say_goodnight(“Mary-Ellen”)
Strings

• Strings in Ruby come in two basic kinds
 • “Double-Quoted”
 • ‘Single-Quoted’
• They differ in how much processing Ruby
  does with their contents
‘Single-Quoted’ Strings


• Ruby does nothing with this kind of string,
  no interpolation, no escape processing,
  nothing
“Double-Quoted” Strings

• Ruby performs additional processing of
  these strings
 • Ruby looks for escape sequences
    n t u2603
 • Ruby also performs interpolation
    #{expression}
Strings

def say_goodnight(name)
  result = “Good night, #{name}“
  return result
end
puts say_goodnight(“John-Boy”)
puts say_goodnight(“Mary-Ellen”)
Methods

def say_goodnight(name)
  result = “Good night, #{name}“
  return result
end
puts say_goodnight(“John-Boy”)
puts say_goodnight(“Mary-Ellen”)
Methods

• Methods are reusable bits of code
• They also go by the name Functions.
• They accept parameters, do something and
  return a value
Methods


• Parameters are passed to methods and
  given convenient local variable names by
  the method definition
Methods

def say_goodnight(name)
  result = “Good night, #{name}“
  return result
end
puts say_goodnight(“John-Boy”)
puts say_goodnight(“Mary-Ellen”)
Methods


• When calling methods the parentheses that
  surround parameters are optional.
• Only leave them out when unambiguous
Methods

def say_goodnight name
  result = “Good night, #{name}“
  return result
end
puts say_goodnight “John-Boy”
puts(say_goodnight “Mary-Ellen”)
Methods

• Methods return values can be either
  explicit or implicit
• Use the return keyword to make explicit
  what your methods return
• Or, the last expression in the method will
  be the methods return value
Methods

def say_goodnight name
  result = “Good night, #{name}“
end
puts say_goodnight “John-Boy”
puts(say_goodnight “Mary-Ellen”)
Our Simplified Sample

def say_goodnight(name)
  “Good night, #{name}“
end
puts say_goodnight(“John-Boy”)
puts say_goodnight(“Mary-Ellen”)
Reviewing

• Objects vs. Classes
• Duck Typing
• Variables
• Strings
• Methods
For Next Week
For the New to Programming
• Read Chapters 2, 3 & 4 in LtP
• Complete exercises for each chapter
For Everyone

• Read Chapter 2 in PR1.9
• Keep playing in IRB
Next Week

• Arrays & Hashes
• Symbols
• Control Structures
• Regular Expressions
• Blocks & Iterators

More Related Content

What's hot

A (very brief) into to Functional Programming
A (very brief) into to Functional ProgrammingA (very brief) into to Functional Programming
A (very brief) into to Functional ProgrammingBrooklyn Zelenka
 
CPP13 - Object Orientation
CPP13 - Object OrientationCPP13 - Object Orientation
CPP13 - Object OrientationMichael Heron
 
2012-02-15 jfokus2012 - regex applied
2012-02-15 jfokus2012 - regex applied2012-02-15 jfokus2012 - regex applied
2012-02-15 jfokus2012 - regex appliedStaffan Nöteberg
 
Comparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value TypesComparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value TypesPéter Verhás
 
Long Live the Rubyist
Long Live the RubyistLong Live the Rubyist
Long Live the Rubyistbaccigalupi
 
Actor-based concurrency and Akka Fundamentals
Actor-based concurrency and Akka FundamentalsActor-based concurrency and Akka Fundamentals
Actor-based concurrency and Akka FundamentalsNgoc Dao
 
How to start using Scala
How to start using ScalaHow to start using Scala
How to start using ScalaNgoc Dao
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threadsmperham
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Rormyuser
 
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)Ashoka R K T
 
Python training in hyderabad
Python training in hyderabadPython training in hyderabad
Python training in hyderabadRajitha D
 
scala reloaded
scala reloadedscala reloaded
scala reloadedMac Liaw
 
Moo the universe and everything
Moo the universe and everythingMoo the universe and everything
Moo the universe and everythingHenry Van Styn
 
Domain driven design @FrOSCon
Domain driven design @FrOSConDomain driven design @FrOSCon
Domain driven design @FrOSConArangoDB Database
 

What's hot (19)

A (very brief) into to Functional Programming
A (very brief) into to Functional ProgrammingA (very brief) into to Functional Programming
A (very brief) into to Functional Programming
 
CPP13 - Object Orientation
CPP13 - Object OrientationCPP13 - Object Orientation
CPP13 - Object Orientation
 
2012-02-15 jfokus2012 - regex applied
2012-02-15 jfokus2012 - regex applied2012-02-15 jfokus2012 - regex applied
2012-02-15 jfokus2012 - regex applied
 
Comparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value TypesComparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value Types
 
Long Live the Rubyist
Long Live the RubyistLong Live the Rubyist
Long Live the Rubyist
 
Actor-based concurrency and Akka Fundamentals
Actor-based concurrency and Akka FundamentalsActor-based concurrency and Akka Fundamentals
Actor-based concurrency and Akka Fundamentals
 
How to start using Scala
How to start using ScalaHow to start using Scala
How to start using Scala
 
Scala days mizushima
Scala days mizushimaScala days mizushima
Scala days mizushima
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Ror
 
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)
 
Introduction to value types
Introduction to value typesIntroduction to value types
Introduction to value types
 
Python training in hyderabad
Python training in hyderabadPython training in hyderabad
Python training in hyderabad
 
Scala.js
Scala.js Scala.js
Scala.js
 
12. Objects I
12. Objects I12. Objects I
12. Objects I
 
scala reloaded
scala reloadedscala reloaded
scala reloaded
 
Ruby Metaprogramming 08
Ruby Metaprogramming 08Ruby Metaprogramming 08
Ruby Metaprogramming 08
 
Moo the universe and everything
Moo the universe and everythingMoo the universe and everything
Moo the universe and everything
 
Domain driven design @FrOSCon
Domain driven design @FrOSConDomain driven design @FrOSCon
Domain driven design @FrOSCon
 

Viewers also liked

Srategic triangulation past, present and possible
Srategic triangulation   past, present and possibleSrategic triangulation   past, present and possible
Srategic triangulation past, present and possibleSharon Johnson
 
The Dancer Life Style Coaching & Training
The Dancer Life Style Coaching & TrainingThe Dancer Life Style Coaching & Training
The Dancer Life Style Coaching & Trainingthedancercoaching
 
3миний хэлэх үг
3миний хэлэх үг3миний хэлэх үг
3миний хэлэх үгGegeen Australia
 
Standard ot sb presentation updated 20130402
Standard ot sb presentation updated 20130402Standard ot sb presentation updated 20130402
Standard ot sb presentation updated 20130402Gegeen Australia
 
Slide set 6 contrasting worldviews in business
Slide set 6   contrasting worldviews in businessSlide set 6   contrasting worldviews in business
Slide set 6 contrasting worldviews in businessSharon Johnson
 
Slide set 7 faith integration in business - stage perspectives
Slide set 7   faith integration in business - stage perspectivesSlide set 7   faith integration in business - stage perspectives
Slide set 7 faith integration in business - stage perspectivesSharon Johnson
 
A systems approach to leading change
A systems approach to leading changeA systems approach to leading change
A systems approach to leading changeSharon Johnson
 
Shinesquad services cards summer 2012
Shinesquad services cards summer 2012Shinesquad services cards summer 2012
Shinesquad services cards summer 2012Shinesquad
 
Michael Colon Portfolio
Michael Colon PortfolioMichael Colon Portfolio
Michael Colon Portfoliomichael_colon
 
The strategy power connection
The strategy power connectionThe strategy power connection
The strategy power connectionSharon Johnson
 
MHP Technology And Telecommunications
MHP Technology And TelecommunicationsMHP Technology And Telecommunications
MHP Technology And TelecommunicationsBen Maynard
 

Viewers also liked (20)

Srategic triangulation past, present and possible
Srategic triangulation   past, present and possibleSrategic triangulation   past, present and possible
Srategic triangulation past, present and possible
 
The Dancer Life Style Coaching & Training
The Dancer Life Style Coaching & TrainingThe Dancer Life Style Coaching & Training
The Dancer Life Style Coaching & Training
 
3миний хэлэх үг
3миний хэлэх үг3миний хэлэх үг
3миний хэлэх үг
 
La descripción
La descripciónLa descripción
La descripción
 
Standard ot sb presentation updated 20130402
Standard ot sb presentation updated 20130402Standard ot sb presentation updated 20130402
Standard ot sb presentation updated 20130402
 
Slide set 6 contrasting worldviews in business
Slide set 6   contrasting worldviews in businessSlide set 6   contrasting worldviews in business
Slide set 6 contrasting worldviews in business
 
1 MglausCom 25112012
1 MglausCom 251120121 MglausCom 25112012
1 MglausCom 25112012
 
Slide set 7 faith integration in business - stage perspectives
Slide set 7   faith integration in business - stage perspectivesSlide set 7   faith integration in business - stage perspectives
Slide set 7 faith integration in business - stage perspectives
 
A systems approach to leading change
A systems approach to leading changeA systems approach to leading change
A systems approach to leading change
 
Ganadores Proyectos de Modding CPCO5
Ganadores Proyectos de Modding CPCO5Ganadores Proyectos de Modding CPCO5
Ganadores Proyectos de Modding CPCO5
 
Shinesquad services cards summer 2012
Shinesquad services cards summer 2012Shinesquad services cards summer 2012
Shinesquad services cards summer 2012
 
Michael Colon Portfolio
Michael Colon PortfolioMichael Colon Portfolio
Michael Colon Portfolio
 
Team buildin gpptx
Team buildin gpptxTeam buildin gpptx
Team buildin gpptx
 
Time management
Time managementTime management
Time management
 
Vivix Consumer
Vivix ConsumerVivix Consumer
Vivix Consumer
 
PART I.1 - Physical Mathematics
PART I.1 - Physical MathematicsPART I.1 - Physical Mathematics
PART I.1 - Physical Mathematics
 
Careers In Financial Services
Careers In Financial ServicesCareers In Financial Services
Careers In Financial Services
 
Creatvity
CreatvityCreatvity
Creatvity
 
The strategy power connection
The strategy power connectionThe strategy power connection
The strategy power connection
 
MHP Technology And Telecommunications
MHP Technology And TelecommunicationsMHP Technology And Telecommunications
MHP Technology And Telecommunications
 

Similar to Learn Ruby 2011 - Session 2

Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010ssoroka
 
Ruby Xml Mapping
Ruby Xml MappingRuby Xml Mapping
Ruby Xml MappingMarc Seeger
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to RubyBarry Jones
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Wen-Tien Chang
 
Ruby Programming Language - Introduction
Ruby Programming Language - IntroductionRuby Programming Language - Introduction
Ruby Programming Language - IntroductionKwangshin Oh
 
Ruby — An introduction
Ruby — An introductionRuby — An introduction
Ruby — An introductionGonçalo Silva
 
Ruby for C# Developers
Ruby for C# DevelopersRuby for C# Developers
Ruby for C# DevelopersCory Foy
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to RubyRyan Cross
 
Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008Brian Sam-Bodden
 
Intro to Ruby/Rails at TechLady Hackathon
Intro to Ruby/Rails at TechLady HackathonIntro to Ruby/Rails at TechLady Hackathon
Intro to Ruby/Rails at TechLady Hackathonkdmcclin
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9sagaroceanic11
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9sagaroceanic11
 
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 2Henry S
 

Similar to Learn Ruby 2011 - Session 2 (20)

Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 
Ruby_Basic
Ruby_BasicRuby_Basic
Ruby_Basic
 
Ruby Xml Mapping
Ruby Xml MappingRuby Xml Mapping
Ruby Xml Mapping
 
Week2
Week2Week2
Week2
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to Ruby
 
4 Expressions and Operators
4  Expressions and Operators4  Expressions and Operators
4 Expressions and Operators
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介
 
Ruby Programming Language - Introduction
Ruby Programming Language - IntroductionRuby Programming Language - Introduction
Ruby Programming Language - Introduction
 
Ruby — An introduction
Ruby — An introductionRuby — An introduction
Ruby — An introduction
 
Ruby for C# Developers
Ruby for C# DevelopersRuby for C# Developers
Ruby for C# Developers
 
Intro to Perl and Bioperl
Intro to Perl and BioperlIntro to Perl and Bioperl
Intro to Perl and Bioperl
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
Learning Ruby
Learning RubyLearning Ruby
Learning Ruby
 
Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008
 
Intro to Ruby/Rails at TechLady Hackathon
Intro to Ruby/Rails at TechLady HackathonIntro to Ruby/Rails at TechLady Hackathon
Intro to Ruby/Rails at TechLady Hackathon
 
Javascript
JavascriptJavascript
Javascript
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
 
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
 

More from James Thompson

Interfaces Not Required — RubyHACK 2018
Interfaces Not Required — RubyHACK 2018Interfaces Not Required — RubyHACK 2018
Interfaces Not Required — RubyHACK 2018James Thompson
 
Bounded Contexts for Legacy Code
Bounded Contexts for Legacy CodeBounded Contexts for Legacy Code
Bounded Contexts for Legacy CodeJames Thompson
 
Beyond Accidental Arcitecture
Beyond Accidental ArcitectureBeyond Accidental Arcitecture
Beyond Accidental ArcitectureJames Thompson
 
Effective Pair Programming
Effective Pair ProgrammingEffective Pair Programming
Effective Pair ProgrammingJames 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 gemJames Thompson
 
Microservices for the Monolith
Microservices for the MonolithMicroservices for the Monolith
Microservices for the MonolithJames Thompson
 
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 RescueJames Thompson
 
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!James Thompson
 
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 3James Thompson
 
Ruby For Web Development
Ruby For Web DevelopmentRuby For Web Development
Ruby For Web DevelopmentJames Thompson
 
Ruby Testing: Cucumber and RSpec
Ruby Testing: Cucumber and RSpecRuby Testing: Cucumber and RSpec
Ruby Testing: Cucumber and RSpecJames Thompson
 

More from James Thompson (12)

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
 
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!
 
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 For Web Development
Ruby For Web DevelopmentRuby For Web Development
Ruby For Web Development
 
Ruby Testing: Cucumber and RSpec
Ruby Testing: Cucumber and RSpecRuby Testing: Cucumber and RSpec
Ruby Testing: Cucumber and RSpec
 

Recently uploaded

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Learn Ruby 2011 - Session 2

  • 1. Learn Ruby 2011 Session 2
  • 3. Welcome Back Ready to learn some Ruby?
  • 5. Learn to Program, 2ed • For total beginners • Systematic coverage of programming concepts • Uses Ruby to teach programming
  • 6. Programming Ruby, 3ed • Comprehensive langauge reference • Covers Ruby 1.9.2, annotations for 1.9 and 1.9.2 specific features • de facto standard reference
  • 7. Language Crashing Learning the basics in pieces
  • 8. Objects vs Classes • An Object is a discreet thing • You can do things to Objects • Classes tell you how to build Objects • Classes in Ruby are also Objects
  • 9. Objects vs Classes • A Car is a Class • My Car is an Object • My Car has lots of things in common with other cars • So, My Car is a Car • But, Not every Car is My Car
  • 10. Everything is an Object • In Ruby everything is an object • This means you can do things to everything you come across.
  • 11. Everything has a Class • Because everything is an Object, everything also has a class • An Object’s class is often referred to as it’s Type
  • 12. Duck Typing • Ruby is Duck Typed • This means that when you encounter an Object in Ruby, what you can do to it determines it’s type • Ruby’s “Type Model” is concerned with what you can do with Objects
  • 13. A Sample of Ruby def say_goodnight(name) result = “Good night, “ + name return result end puts say_goodnight(“John-Boy”) puts say_goodnight(“Mary-Ellen”)
  • 14. Variables def say_goodnight(name) result = “Good night, “ + name return result end puts say_goodnight(“John-Boy”) puts say_goodnight(“Mary-Ellen”)
  • 15. Variables • Variables hold values, in Ruby they hold Objects • Variables are the handles we use to easily reference the data we want to work with
  • 16. Variables • There are four basic kinds of variables • local_variables • @instance_variables • @@class_variables • $global_variables
  • 17. Variables • There are also Constants, variables that don’t change • ClassNames • CONSTANT_NAME
  • 18. Variables def say_goodnight(name) result = “Good night, “ + name return result end puts say_goodnight(“John-Boy”) puts say_goodnight(“Mary-Ellen”)
  • 19. Strings def say_goodnight(name) result = “Good night, “ + name return result end puts say_goodnight(“John-Boy”) puts say_goodnight(“Mary-Ellen”)
  • 20. Strings • Strings in Ruby come in two basic kinds • “Double-Quoted” • ‘Single-Quoted’ • They differ in how much processing Ruby does with their contents
  • 21. ‘Single-Quoted’ Strings • Ruby does nothing with this kind of string, no interpolation, no escape processing, nothing
  • 22. “Double-Quoted” Strings • Ruby performs additional processing of these strings • Ruby looks for escape sequences n t u2603 • Ruby also performs interpolation #{expression}
  • 23. Strings def say_goodnight(name) result = “Good night, #{name}“ return result end puts say_goodnight(“John-Boy”) puts say_goodnight(“Mary-Ellen”)
  • 24. Methods def say_goodnight(name) result = “Good night, #{name}“ return result end puts say_goodnight(“John-Boy”) puts say_goodnight(“Mary-Ellen”)
  • 25. Methods • Methods are reusable bits of code • They also go by the name Functions. • They accept parameters, do something and return a value
  • 26. Methods • Parameters are passed to methods and given convenient local variable names by the method definition
  • 27. Methods def say_goodnight(name) result = “Good night, #{name}“ return result end puts say_goodnight(“John-Boy”) puts say_goodnight(“Mary-Ellen”)
  • 28. Methods • When calling methods the parentheses that surround parameters are optional. • Only leave them out when unambiguous
  • 29. Methods def say_goodnight name result = “Good night, #{name}“ return result end puts say_goodnight “John-Boy” puts(say_goodnight “Mary-Ellen”)
  • 30. Methods • Methods return values can be either explicit or implicit • Use the return keyword to make explicit what your methods return • Or, the last expression in the method will be the methods return value
  • 31. Methods def say_goodnight name result = “Good night, #{name}“ end puts say_goodnight “John-Boy” puts(say_goodnight “Mary-Ellen”)
  • 32. Our Simplified Sample def say_goodnight(name) “Good night, #{name}“ end puts say_goodnight(“John-Boy”) puts say_goodnight(“Mary-Ellen”)
  • 33. Reviewing • Objects vs. Classes • Duck Typing • Variables • Strings • Methods
  • 34. For Next Week For the New to Programming • Read Chapters 2, 3 & 4 in LtP • Complete exercises for each chapter For Everyone • Read Chapter 2 in PR1.9 • Keep playing in IRB
  • 35. Next Week • Arrays & Hashes • Symbols • Control Structures • Regular Expressions • Blocks & Iterators

Editor's Notes

  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
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n