Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Learning Ruby
A Note Regarding Supplemental Files
Preface
Who Should Read This Book?
How This Book Works
About the Examples
How This Book Is Organized
Conventions Used in This Book
Comments and Questions
SafariĀ® Enabled
Acknowledgments
1. Ruby Basics
Hello, Matz
A Very Short Ruby Program
Shebang!
Issue a System Command
Appending a String
Multiply
Inserting a Shell Command
Using a Variable
Expression Substitution
Formatting a String
The eval Method and -e Option
Getting Input from the Keyboard
Methods
The block
The each Method
The proc
XML
The Class
The Tk Toolkit
Editing and Running Ruby in TextMate
Interactive Ruby
Resources
Installing Ruby
Installing Ruby on Mac OS X Tiger
Installing Ruby on Windows with the One-Click Installer
Installing Ruby on Windows with Binaries
Installing Ruby on Linux
Permission Denied
Associating File Types on Windows
Review Questions
2. A Quick Tour of Ruby
Ruby Is Object-Oriented
The Object Class and the Kernel Module
Ruby's Reserved Words
Comments
Variables
Local Variables
Instance Variables
Class Variables
Global Variables
Constants
Parallel Assignment
Strings
Regular Expressions
Numbers and Operators
Conditional Statements
Arrays and Hashes
Methods
Return Values
Method Name Conventions
Default Arguments
Variable Arguments
Aliasing Methods
Blocks
The yield Statement
Procs
Symbols
Exception Handling
Ruby Documentation
Review Questions
3. Conditional Love
The if Statement
Using else and elsif
The Ternary Operator
The case Statement
The while Loop
Give me a break
unless and until
The loop Method
The for loop
The times Method
The upto Method
The downto Method
Execution Before or After a Program
Review Questions
4. Strings
Creating Strings
General Delimited Strings
Here Documents
Concatenating Strings
Accessing Strings
Comparing Strings
Manipulating Strings
Inserting a String in a String
Changing All or Part of a String
The chomp and chop Methods
The delete Method
Substitute the Substring
Turn It Around
From a String to an Array
Case Conversion
Iterating Over a String
downcase, upcase, and swapcase
Managing Whitespace, etc.
Incrementing Strings
Converting Strings
Regular Expressions
1.9 and Beyond
Review Questions
5. Math
Class Hierarchy and Included Modules
Converting Numbers
Basic Math Operations
Division and Truncation
Equality, Less Than, or Greater Than
Abbreviated Assignment Operators
Operators
Ranges
Inquiring About Numbers
Iterating Through Blocks
More Math Methods
Math Functions
Rational Numbers
Prime Numbers
Just for Fun
Review Questions
6. Arrays
Creating Arrays
Clear the Deck
Creating an Array with a Block
There's an Easier Way
It Gets Even Easier
Accessing Elements
Concatenation
Set Operations
Unique Elements
Blow Your Stack
Comparing Arrays
Changing Elements
As a String
Using shift and unshift
Deleting Elements
Arrays and Blocks
Sorting Things and About Face
Multidimensional Arrays
1.9 and Beyond
Other Array Methods
Review Questions
7. Hashes
Creating Hashes
Accessing Hashes
Iterating over Hashes
Changing Hashes
Merging Hashes
Sorting a Hash
Deleting and Clearing a Hash
Replacing a Hash
Converting Hashes to Other Classes
1.9 and Beyond
Other Hash Methods
Review Questions
8. Working with Files
Directories
Looking Inside Directories
The Directory Stream
Creating a New File
Opening an Existing File
ARGV and ARGF
Opening a URI
Deleting and Renaming Files
File Inquiries
Changing File Modes and Owner
The IO Class
Review Questions
9. Classes
Defining the Class
Instance Variables
Accessors
Class Variables
Class Methods
Singletons
Inheritance
Modules
public, private, or protected
Review Questions
10. More Fun with Ruby
Formatting Output with sprintf
Processing XML
REXML
Builder
Date and Time
The Time Class
The Date Class
Calendar forms
Reflection
Reflection on Variables and Constants
Reflection on Methods
Using Tk
Metaprogramming
RubyGems
Exception Handling
Creating Documentation with RDoc
RDoc Basics
Processing Files with RDoc
Embedded Ruby
Review Questions
11. A Short Guide to Ruby on Rails
Where Did Rails Come From
Why Rails?
A Full-Stack Framework
Don't Repeat Yourself
Convention over Configuration
I Want My MVC
Scripts
Validation
Ajax
Migrations
Console
Environments and Testing
Capistrano
Rake
What Have Other Folks Done with Rails?
Hosting Rails
Installing Rails
Using RubyGems to install Rails
Other Installation Information
Learning Rails
Ruby Tutorials and Books
A Brief Tutorial
Review Questions
A. Ruby Reference
Ruby Interpreter
Ruby's Reserved Words
Operators
Escape Characters
Predefined Variables
Global Constants
Regular Expressions
String Unpack Directives
Array Pack Directives
Sprintf Flags and Field Types
File Tests
Time Formatting Directives
RDoc Options
Rake
B. Answers to Review Questions
Chapter 1 Review Questions
Chapter 2 Review Questions
Chapter 3 Review Questions
Chapter 4 Review Questions
Chapter 5 Review Questions
Chapter 6 Review Questions
Chapter 7 Review Questions
Chapter 8 Review Questions
Chapter 9 Review Questions
Chapter 10 Review Questions
Chapter 11 Review Questions
Glossary
Index
Colophon
← Prev
Back
Next →
← Prev
Back
Next →