SlideShare a Scribd company logo
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 Programming
Brooklyn Zelenka
 
CPP13 - Object Orientation
CPP13 - Object OrientationCPP13 - Object Orientation
CPP13 - Object Orientation
Michael Heron
 
2012-02-15 jfokus2012 - regex applied
2012-02-15 jfokus2012 - regex applied2012-02-15 jfokus2012 - regex applied
2012-02-15 jfokus2012 - regex applied
Staffan 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 Types
Péter Verhás
 
Long Live the Rubyist
Long Live the RubyistLong Live the Rubyist
Long Live the Rubyist
baccigalupi
 
Actor-based concurrency and Akka Fundamentals
Actor-based concurrency and Akka FundamentalsActor-based concurrency and Akka Fundamentals
Actor-based concurrency and Akka Fundamentals
Ngoc Dao
 
How to start using Scala
How to start using ScalaHow to start using Scala
How to start using Scala
Ngoc Dao
 
Scala days mizushima
Scala days mizushimaScala days mizushima
Scala days mizushima
Skills Matter Talks
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
mperham
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Ror
myuser
 
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
 
Introduction to value types
Introduction to value typesIntroduction to value types
Introduction to value types
Narendran Solai Sridharan
 
Python training in hyderabad
Python training in hyderabadPython training in hyderabad
Python training in hyderabad
Rajitha D
 
Scala.js
Scala.js Scala.js
12. Objects I
12. Objects I12. Objects I
12. Objects I
Joseph Murphy
 
scala reloaded
scala reloadedscala reloaded
scala reloaded
Mac Liaw
 
Ruby Metaprogramming 08
Ruby Metaprogramming 08Ruby Metaprogramming 08
Ruby Metaprogramming 08
Brian Sam-Bodden
 
Moo the universe and everything
Moo the universe and everythingMoo the universe and everything
Moo the universe and everything
Henry Van Styn
 
Domain driven design @FrOSCon
Domain driven design @FrOSConDomain driven design @FrOSCon
Domain driven design @FrOSCon
ArangoDB 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 possible
Sharon 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
 
La descripción
La descripciónLa descripción
La descripción
Jocelyne Gonzalez Thieme
 
Standard ot sb presentation updated 20130402
Standard ot sb presentation updated 20130402Standard ot sb presentation updated 20130402
Standard ot sb presentation updated 20130402
Gegeen 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 business
Sharon Johnson
 
1 MglausCom 25112012
1 MglausCom 251120121 MglausCom 25112012
1 MglausCom 25112012
Gegeen Australia
 
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
Sharon Johnson
 
A systems approach to leading change
A systems approach to leading changeA systems approach to leading change
A systems approach to leading change
Sharon Johnson
 
Ganadores Proyectos de Modding CPCO5
Ganadores Proyectos de Modding CPCO5Ganadores Proyectos de Modding CPCO5
Ganadores Proyectos de Modding CPCO5
Juan Sebastian Campos Zapata
 
Shinesquad services cards summer 2012
Shinesquad services cards summer 2012Shinesquad services cards summer 2012
Shinesquad services cards summer 2012
Shinesquad
 
Michael Colon Portfolio
Michael Colon PortfolioMichael Colon Portfolio
Michael Colon Portfolio
michael_colon
 
Team buildin gpptx
Team buildin gpptxTeam buildin gpptx
Team buildin gpptx
Edventures1 Learning Solutions
 
Time management
Time managementTime management
Vivix Consumer
Vivix ConsumerVivix Consumer
Vivix Consumer
Stacey Howard
 
PART I.1 - Physical Mathematics
PART I.1 - Physical MathematicsPART I.1 - Physical Mathematics
PART I.1 - Physical Mathematics
Maurice R. TREMBLAY
 
Careers In Financial Services
Careers In Financial ServicesCareers In Financial Services
Careers In Financial Services
Edventures1 Learning Solutions
 
Creatvity
CreatvityCreatvity
The strategy power connection
The strategy power connectionThe strategy power connection
The strategy power connection
Sharon Johnson
 
MHP Technology And Telecommunications
MHP Technology And TelecommunicationsMHP Technology And Telecommunications
MHP Technology And Telecommunications
Ben 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 2010
ssoroka
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
Tushar Pal
 
Ruby_Basic
Ruby_BasicRuby_Basic
Ruby_Basic
Kushal Jangid
 
Ruby Xml Mapping
Ruby Xml MappingRuby Xml Mapping
Ruby Xml Mapping
Marc Seeger
 
Week2
Week2Week2
Week2
reneedv
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to Ruby
Barry Jones
 
4 Expressions and Operators
4  Expressions and Operators4  Expressions and Operators
4 Expressions and Operators
Deepak Hagadur Bheemaraju
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介
Wen-Tien Chang
 
Ruby Programming Language - Introduction
Ruby Programming Language - IntroductionRuby Programming Language - Introduction
Ruby Programming Language - Introduction
Kwangshin Oh
 
Ruby — An introduction
Ruby — An introductionRuby — An introduction
Ruby — An introduction
Gonçalo Silva
 
Ruby for C# Developers
Ruby for C# DevelopersRuby for C# Developers
Ruby for C# Developers
Cory Foy
 
Intro to Perl and Bioperl
Intro to Perl and BioperlIntro to Perl and Bioperl
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
Ryan Cross
 
Learning Ruby
Learning RubyLearning Ruby
Learning Ruby
David Francisco
 
Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008
Brian 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 Hackathon
kdmcclin
 
Javascript
JavascriptJavascript
Javascript
Sunil Thakur
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
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
Henry 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 2018
James Thompson
 
Bounded Contexts for Legacy Code
Bounded Contexts for Legacy CodeBounded Contexts for Legacy Code
Bounded Contexts for Legacy Code
James Thompson
 
Beyond Accidental Arcitecture
Beyond Accidental ArcitectureBeyond Accidental Arcitecture
Beyond Accidental Arcitecture
James Thompson
 
Effective Pair Programming
Effective Pair ProgrammingEffective Pair Programming
Effective Pair Programming
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
 
Microservices for the Monolith
Microservices for the MonolithMicroservices for the Monolith
Microservices for the Monolith
James Thompson
 
Mocking & Stubbing
Mocking & StubbingMocking & Stubbing
Mocking & Stubbing
James 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 Rescue
James 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 3
James Thompson
 
Ruby For Web Development
Ruby For Web DevelopmentRuby For Web Development
Ruby For Web Development
James Thompson
 
Ruby Testing: Cucumber and RSpec
Ruby Testing: Cucumber and RSpecRuby Testing: Cucumber and RSpec
Ruby Testing: Cucumber and RSpec
James 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

Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
jpupo2018
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 

Recently uploaded (20)

Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 

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