SlideShare ist ein Scribd-Unternehmen logo
1 von 52
Chapter 2 Interacting with Ruby Ruby Programming
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Objectives Ruby Programming
Project Preview: The Ruby Tall Tale Game   Ruby Programming
The Ruby Tall Tale Game (continued) ,[object Object],Ruby Programming Figure 2-1 An invitation to play the Ruby Tall Tale game as it would appear on a Mac OS X screen.
The Ruby Tall Tale Game (continued) ,[object Object],Ruby Programming Figure 2-2 The game encourages the player to play some other time.
The Ruby Tall Tale Game (continued) ,[object Object],Ruby Programming Figure 2-3 The player is asked to provide the first of five pieces of information.
The Ruby Tall Tale Game (continued) ,[object Object],Ruby Programming Figure 2-4 Like many good stories, the Ruby Tall Tale game begins setting the scene and introducing its heroes.
The Ruby Tall Tale Game (continued) ,[object Object],Ruby Programming Figure 2-5 The story introduces the villain and establishes the need for heroes.
The Ruby Tall Tale Game (continued) ,[object Object],Ruby Programming Figure 2-6 The story paints a picture of desperation and identifies the challenge its heroes face.
The Ruby Tall Tale Game (continued) ,[object Object],Ruby Programming Figure 2-7 In the end, the people are saved and the heroes return to their homes.
The Ruby Tall Tale Game (continued) ,[object Object],Ruby Programming Figure 2-8 The game ends after thanking the player.
Getting to Know the IRB Ruby Programming
Starting an IRB Session ,[object Object],[object Object],[object Object],[object Object],Ruby Programming
Starting an IRB Session  (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming
Starting an IRB Session   (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming
Working with Multiple IRB Sessions  ,[object Object],[object Object],[object Object],[object Object],Ruby Programming
Accessing IRB Online  Ruby Programming
Accessing the IRB Online  (continued) Ruby Programming Figure 2-9 The Try Ruby! web page provides online access to IRB.
Working with IRB Ruby Programming
Executing Ruby Statements  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming
Executing Ruby Statements  (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming
Following Ruby’s Syntax Rules ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming
Executing Incomplete Statements  ,[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming
Using IRB to Test Ruby Scripts  ,[object Object],[object Object],[object Object],[object Object],Ruby Programming
Using the IRB to Perform Mathematical Calculations  Ruby Programming
Ruby Math Operators ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming
Using IRB as a Calculator  ,[object Object],[object Object],[object Object],[object Object],Ruby Programming
Accessing Methods Stored in the  Math  Module  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming
Operator Precedence  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming
Overriding Operator Precedence ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming
Integers Versus Floating-Point Numbers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming
Accessing Ruby Documentation Ruby Programming
Reviewing Ruby Documentation ,[object Object],[object Object],Ruby Programming Figure 2-10 Accessing Ruby documentation at www.ruby-doc.org.
Reviewing Ruby Documentation  (continued) ,[object Object],[object Object],Ruby Programming Figure 2-11 Using ri to view documentation about Ruby’s  Numeric  class.
Reviewing Ruby Documentation  (continued) ,[object Object],[object Object],Ruby Programming Figure 2-12 Using ri to view documentation about the  Numeric  class’s  round  method.
Back to the Ruby Tall Tale Game Ruby Programming
Designing the Game ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming
Step 1: Creating a New Ruby File  ,[object Object],[object Object],Ruby Programming
Step 2: Documenting the Script and Its Purpose  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming
Step 3: Defining Custom Classes  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming The first class is named  Screen , and it contains a method named  cls  that when called will clear the terminal window  The second class is named  Tale , and it defines properties representing key components of the game’s story plot.
Step 4: Preparing the Game for Execution  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming
Step 5: Outlining the Script’s High-Level Conditional Logic ,[object Object],[object Object],[object Object],[object Object],Ruby Programming
Step 6: Prematurely Terminating Game Execution ,[object Object],[object Object],[object Object],Ruby Programming
Step 7: Collecting Player Input ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming
Step 7: Collecting Player Input (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming
Step 8: Building the Game’s Story  ,[object Object],[object Object],[object Object],[object Object],Ruby Programming
Step 8: Building the Game’s Story  (continued) ,[object Object],[object Object],[object Object],[object Object],Ruby Programming
Step 8: Building the Game’s Story  (continued) ,[object Object],[object Object],[object Object],Ruby Programming
Step 9: Telling the Game’s Story ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ruby Programming These statements are grouped into sets. Each set begins by calling on the  Screen  class’s  cls  method to clear the console window. The  Tale  class’s  tell_Story  method is then called and passed a paragraph to display. The  STDIN  class’s  gets  method is then run in order to pause the execution of the script until the player presses the Enter key.
Step 10: Thanking the Player  ,[object Object],[object Object],[object Object],[object Object],Ruby Programming
Running Your New Ruby Script Game  ,[object Object],[object Object],[object Object],[object Object],Ruby Programming
Summary Ruby Programming ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Weitere ähnliche Inhalte

Was ist angesagt?

C programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti DokeC programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti DokePranoti Doke
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in Carshpreetkaur07
 
Strings-Computer programming
Strings-Computer programmingStrings-Computer programming
Strings-Computer programmingnmahi96
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programmingnmahi96
 
String Analysis for JavaScript Programs
String Analysis for JavaScript ProgramsString Analysis for JavaScript Programs
String Analysis for JavaScript ProgramsSerena King
 
JRuby, Not Just For Hard-Headed Pragmatists Anymore
JRuby, Not Just For Hard-Headed Pragmatists AnymoreJRuby, Not Just For Hard-Headed Pragmatists Anymore
JRuby, Not Just For Hard-Headed Pragmatists AnymoreErin Dees
 
Write Your Own JVM Compiler
Write Your Own JVM CompilerWrite Your Own JVM Compiler
Write Your Own JVM CompilerErin Dees
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsKuntal Bhowmick
 
C programming session 05
C programming session 05C programming session 05
C programming session 05Dushmanta Nath
 
Your Own Metric System
Your Own Metric SystemYour Own Metric System
Your Own Metric SystemErin Dees
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2ndConnex
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming CourseDennis Chang
 
Thnad's Revenge
Thnad's RevengeThnad's Revenge
Thnad's RevengeErin Dees
 
Exercises on Advances in Verification Methodologies
Exercises on Advances in Verification Methodologies Exercises on Advances in Verification Methodologies
Exercises on Advances in Verification Methodologies Ramdas Mozhikunnath
 
12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cpp12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cppsharvivek
 

Was ist angesagt? (20)

C programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti DokeC programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti Doke
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in C
 
Strings-Computer programming
Strings-Computer programmingStrings-Computer programming
Strings-Computer programming
 
Structures-2
Structures-2Structures-2
Structures-2
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
 
String Analysis for JavaScript Programs
String Analysis for JavaScript ProgramsString Analysis for JavaScript Programs
String Analysis for JavaScript Programs
 
JRuby, Not Just For Hard-Headed Pragmatists Anymore
JRuby, Not Just For Hard-Headed Pragmatists AnymoreJRuby, Not Just For Hard-Headed Pragmatists Anymore
JRuby, Not Just For Hard-Headed Pragmatists Anymore
 
Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)
 
Write Your Own JVM Compiler
Write Your Own JVM CompilerWrite Your Own JVM Compiler
Write Your Own JVM Compiler
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
 
Your Own Metric System
Your Own Metric SystemYour Own Metric System
Your Own Metric System
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
 
C tutorials
C tutorialsC tutorials
C tutorials
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Thnad's Revenge
Thnad's RevengeThnad's Revenge
Thnad's Revenge
 
Exercises on Advances in Verification Methodologies
Exercises on Advances in Verification Methodologies Exercises on Advances in Verification Methodologies
Exercises on Advances in Verification Methodologies
 
The smartpath information systems c plus plus
The smartpath information systems  c plus plusThe smartpath information systems  c plus plus
The smartpath information systems c plus plus
 
12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cpp12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cpp
 

Ähnlich wie Ruby Chapter 2

Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on RailsManoj Kumar
 
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...Matt Gauger
 
Ruby on Rails introduction
Ruby on Rails introduction Ruby on Rails introduction
Ruby on Rails introduction Tran Hung
 
C from hello world to 010101
C from hello world to 010101C from hello world to 010101
C from hello world to 010101Bellaj Badr
 
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012rivierarb
 
Ruby Presentation
Ruby Presentation Ruby Presentation
Ruby Presentation platico_dev
 
Page List & Sample Material (Repaired)
Page List & Sample Material (Repaired)Page List & Sample Material (Repaired)
Page List & Sample Material (Repaired)Muhammad Haseeb Shahid
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deploymentThilo Utke
 
Intro to Ruby on Rails
Intro to Ruby on RailsIntro to Ruby on Rails
Intro to Ruby on Railselpizoch
 
Ruby On Rails Introduction
Ruby On Rails IntroductionRuby On Rails Introduction
Ruby On Rails IntroductionThomas Fuchs
 
An introduction-to-ruby-on-rails
An introduction-to-ruby-on-railsAn introduction-to-ruby-on-rails
An introduction-to-ruby-on-railsvinicorp
 
An Introduction to Ruby on Rails 20100506
An Introduction to Ruby on Rails 20100506An Introduction to Ruby on Rails 20100506
An Introduction to Ruby on Rails 20100506Vu Hung Nguyen
 
P4 P Update January 2009
P4 P Update January 2009P4 P Update January 2009
P4 P Update January 2009vsainteluce
 
The details of CI/CD environment for Ruby
The details of CI/CD environment for RubyThe details of CI/CD environment for Ruby
The details of CI/CD environment for RubyHiroshi SHIBATA
 
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar BatsovRuby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar BatsovMichael Kimathi
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby BasicsSHC
 

Ähnlich wie Ruby Chapter 2 (20)

Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
 
Ruby on Rails introduction
Ruby on Rails introduction Ruby on Rails introduction
Ruby on Rails introduction
 
C from hello world to 010101
C from hello world to 010101C from hello world to 010101
C from hello world to 010101
 
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
 
Ruby Presentation
Ruby Presentation Ruby Presentation
Ruby Presentation
 
Page List & Sample Material (Repaired)
Page List & Sample Material (Repaired)Page List & Sample Material (Repaired)
Page List & Sample Material (Repaired)
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deployment
 
Intro to Ruby on Rails
Intro to Ruby on RailsIntro to Ruby on Rails
Intro to Ruby on Rails
 
How DSL works on Ruby
How DSL works on RubyHow DSL works on Ruby
How DSL works on Ruby
 
Ruby On Rails Introduction
Ruby On Rails IntroductionRuby On Rails Introduction
Ruby On Rails Introduction
 
An introduction-to-ruby-on-rails
An introduction-to-ruby-on-railsAn introduction-to-ruby-on-rails
An introduction-to-ruby-on-rails
 
An Introduction to Ruby on Rails 20100506
An Introduction to Ruby on Rails 20100506An Introduction to Ruby on Rails 20100506
An Introduction to Ruby on Rails 20100506
 
03 ruby environment
03 ruby environment03 ruby environment
03 ruby environment
 
P4 P Update January 2009
P4 P Update January 2009P4 P Update January 2009
P4 P Update January 2009
 
Ebay News 2000 10 19 Earnings
Ebay News 2000 10 19 EarningsEbay News 2000 10 19 Earnings
Ebay News 2000 10 19 Earnings
 
Ebay News 2001 4 19 Earnings
Ebay News 2001 4 19 EarningsEbay News 2001 4 19 Earnings
Ebay News 2001 4 19 Earnings
 
The details of CI/CD environment for Ruby
The details of CI/CD environment for RubyThe details of CI/CD environment for Ruby
The details of CI/CD environment for Ruby
 
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar BatsovRuby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby Basics
 

Mehr von Chaffey College (20)

Social networks and games
Social networks and gamesSocial networks and games
Social networks and games
 
Serious games
Serious gamesSerious games
Serious games
 
Chapter 05
Chapter 05Chapter 05
Chapter 05
 
Chapter 04
Chapter 04Chapter 04
Chapter 04
 
Chapter 03
Chapter 03Chapter 03
Chapter 03
 
The games factory 2 alien wars
The games factory 2 alien warsThe games factory 2 alien wars
The games factory 2 alien wars
 
Target markets
Target marketsTarget markets
Target markets
 
Ch 8 introduction to data structures
Ch 8 introduction to data structuresCh 8 introduction to data structures
Ch 8 introduction to data structures
 
Ch 8 data structures in alice
Ch 8  data structures in aliceCh 8  data structures in alice
Ch 8 data structures in alice
 
Ch 7 recursion
Ch 7 recursionCh 7 recursion
Ch 7 recursion
 
Intro to gml
Intro to gmlIntro to gml
Intro to gml
 
Power point unit d
Power point unit dPower point unit d
Power point unit d
 
Power point unit c
Power point unit cPower point unit c
Power point unit c
 
Power point unit b
Power point unit bPower point unit b
Power point unit b
 
Power point unit a
Power point unit aPower point unit a
Power point unit a
 
Gamegraphics
GamegraphicsGamegraphics
Gamegraphics
 
Gamesound
GamesoundGamesound
Gamesound
 
Ch 6 text and sound in alice
Ch 6 text and sound in aliceCh 6 text and sound in alice
Ch 6 text and sound in alice
 
Ch 5 boolean logic
Ch 5 boolean logicCh 5 boolean logic
Ch 5 boolean logic
 
Ch 5 boolean logical in alice
Ch 5  boolean logical in aliceCh 5  boolean logical in alice
Ch 5 boolean logical in alice
 

Ruby Chapter 2