You are previewing Computer Science Programming Basics in Ruby.
O'Reilly logo
Computer Science Programming Basics in Ruby

Book Description

If you know basic high-school math, you can quickly learn and apply the core concepts of computer science with this concise, hands-on book. Led by a team of experts, you’ll quickly understand the difference between computer science and computer programming, and you’ll learn how algorithms help you solve computing problems.

Table of Contents

  1. Preface
    1. Conventions Used in This Book
    2. Using Code Examples
    3. Safari® Books Online
    4. How to Contact Us
    5. Acknowledgments
  2. 1. Introduction to Computer Science
    1. 1.1 Introduction
    2. 1.2 Application Development
      1. Step 1: Understand the Problem
      2. Step 2: Write Out the Solution in Plain Language
      3. Step 3: Translate the Language into Code
      4. Step 4: Test the Code in the Computer
    3. 1.3 Algorithms
      1. 1.3.1 Algorithm Efficiency
    4. 1.4 Summary
      1. 1.4.1 Key Concepts
      2. 1.4.2 Key Definitions
    5. 1.5 Exercises
  3. 2. How Does the Computer Really Work?
    1. 2.1 Introduction
    2. 2.2 Basic Nomenclature and Components of a Computer System
    3. 2.3 Scales of Magnitude
    4. 2.4 Instruction Execution—Speed and Timing Scales
    5. 2.5 Bit Strings and Their Meaning
    6. 2.6 The Interpreter Process and Ruby
    7. 2.7 Summary
      1. 2.7.1 Key Concepts
      2. 2.7.2 Key Definitions
    8. 2.8 Exercises
  4. 3. Core Programming Elements
    1. 3.1 Introduction
    2. 3.2 Getting Started
      1. How to Install Ruby
      2. How to Save Programs
    3. 3.3 What Is a Variable?
      1. Constants: Variables That Never Change
      2. Data Types
      3. Integer
      4. Float
      5. Strings
      6. Booleans
    4. 3.4 Basic Arithmetic Operators
    5. 3.5 Input and Output
      1. Output Using Variables
      2. Display User Input
      3. Basic Programs
      4. Step 1: Understanding the Problem
      5. Step 2: Write Out the Problem in Plain Language
      6. Step 3: Rewrite the Plain Language into Code
      7. Step 4: Test the Code in the Computer
    6. 3.6 Common Programming Errors
      1. Syntax Errors
      2. Logic Errors
    7. 3.7 Mixing Data Types
    8. 3.8 Summary
      1. 3.8.1 Key Concepts
      2. 3.8.2 Key Definitions
    9. 3.9 Exercises
  5. 4. Conditional Structures
    1. 4.1 Introduction
    2. 4.2 Flow of Execution
      1. Logic Flow
    3. 4.3 Conditional Control
      1. Control Flow
    4. 4.4 If-Then-Else Statements
      1. Testing Conditional Flow
      2. Elsif Statements
    5. 4.5 Case Statements
    6. 4.6 Debugging
      1. 4.6.1 Alternative Styles of Debugging
    7. 4.7 Summary
      1. 4.7.1 Key Concepts
      2. 4.7.2 Key Definitions
    8. 4.8 Exercises
  6. 5. Loop Structures
    1. 5.1 Introduction
    2. 5.2 While Loops
    3. 5.3 Until Loops
    4. 5.4 For Loops and Nested Loops
      1. For Loops
      2. Nested Loops
    5. 5.5 Infinite Loops
    6. 5.6 Example: Finding Prime Numbers
    7. 5.7 Summary
      1. 5.7.1 Key Concepts
      2. 5.7.2 Key Definitions
    8. 5.8 Exercises
  7. 6. Arrays
    1. 6.1 Introduction
    2. 6.2 Array Types
      1. 6.2.1 One-Dimensional Arrays
      2. Example: Find the Max
      3. 6.2.2 Multidimensional Arrays
      4. Example: Find the Max—Modified
    3. 6.3 Hashes
      1. Example: Hash
      2. Example: Accessing a Hash
      3. Example: Find the Max—Hash
    4. 6.4 Summary
      1. 6.4.1 Key Concepts
      2. 6.4.2 Key Definitions
    5. 6.5 Exercises
  8. 7. Sorting and Searching
    1. 7.1 Introduction
      1. 7.1.1 Selection Sort
      2. 7.1.2 Insertion Sort
      3. 7.1.3 Bubble Sort
      4. 7.1.4 Radix Sort
    2. 7.2 Complexity Analysis
    3. 7.3 Searching
      1. 7.3.1 Linear Search
      2. 7.3.2 Binary Search
    4. 7.4 Summary
      1. 7.4.1 Key Concepts
      2. 7.4.2 Key Definitions
    5. 7.5 Exercises
  9. 8. Using Objects
    1. 8.1 Introduction
    2. 8.2 Objects and Built-in Objects
      1. 8.2.1 Objects
      2. 8.2.2 Built-in Objects
      3. 8.2.3 Parameter Passing
    3. 8.3 Summary
      1. 8.3.1 Key Concepts
      2. 8.3.2 Key Definitions
    4. 8.4 Exercises
  10. 9. Defining Classes and Creating Objects
    1. 9.1 Introduction
    2. 9.2 Instantiating Objects from Classes
    3. 9.3 Data and Methods
      1. 9.3.1 Grouping Data and Methods
      2. 9.3.2 Implementing Methods
    4. 9.4 Summary
      1. 9.4.1 Key Concepts
      2. 9.4.2 Key Definitions
    5. 9.5 Exercises
  11. 10. Object Inheritance
    1. 10.1 Introduction
    2. 10.2 Inheritance
    3. 10.3 Basic Method Overriding
    4. 10.4 Accessing the Superclass
    5. 10.5 Applications
      1. 10.5.1 Person Database
      2. 10.5.2 Grocery Store
      3. 10.5.3 Video Games
    6. 10.6 Summary
      1. 10.6.1 Key Concepts
      2. 10.6.2 Key Definitions
    7. 10.7 Exercises
  12. 11. File Input/Output
    1. 11.1 Introduction
    2. 11.2 File Access: Reading and Writing
      1. 11.2.1 File Reader Class
      2. 11.2.2 FileWriter Class
      3. 11.2.3 File Reader/Writer Example
    3. 11.3 Summary
      1. 11.3.1 Key Concepts
      2. 11.3.2 Key Definitions
    4. 11.4 Exercises
  13. 12. Putting It All Together: Tic-Tac-Toe
    1. 12.1 Introduction
    2. 12.2 Programming Approach
    3. 12.3 Tic-Tac-Toe
    4. 12.4 Tic-Tac-Toe Revised
    5. 12.5 Summary
    6. 12.6 Exercises
  14. A. Recommended Additional Reading
    1. A.1 OS Reading Material
    2. A.2 Ruby Documentation
    3. A.3 Algorithm and Complexity Reading Material
  15. B. Installing Ruby
    1. B.1 Windows
    2. B.2 Linux
    3. B.3 Mac OS X
  16. C. Writing Code for Ruby
    1. C.1 Windows
    2. C.2 Linux
    3. C.3 Mac OS X
    4. C.4 General Information
  17. D. Using irb
  18. Colophon
  19. Copyright