Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
The Book of Ruby
Acknowledgments
Introduction
What Is Ruby?
What Is Rails?
Matters of Ruby Style
How to Read This Book
Digging Deeper
Making Sense of the Text
Downloading Ruby
Getting the Source Code of the Sample Programs
Running Ruby Programs
The Ruby Library Documentation
1. Strings, Numbers, Classes, and Objects
Getting and Putting Input
Strings and Embedded Evaluation
Numbers
Comments
Testing a Condition: if..then
Local and Global Variables
Classes and Objects
Instance Variables
Retrieving Data from an Object
Messages, Methods, and Polymorphism
Constructors: new and initialize
Inspecting Objects
2. Class Hierarchies, Attributes, and Class Variables
Superclasses and Subclasses
Passing Arguments to the Superclass
Accessor Methods
Attribute Readers and Writers
Calling Methods of a Superclass
Class Variables
3. Strings and Ranges
User-Defined String Delimiters
Backquotes
String Handling
Concatenation
What About Commas?
String Assignment
Indexing into a String
Removing Newline Characters: chop and chomp
Format Strings
Ranges
Ranges of Strings
Iterating with a Range
4. Arrays and Hashes
Arrays
Creating Arrays
Multidimensional Arrays
Iterating over Arrays
Indexing into Arrays
Copying Arrays
Testing Arrays for Equality
Sorting Arrays
Comparing Values
Array Methods
Hashes
Creating Hashes
Indexing into a Hash
Copying a Hash
Hash Order
Sorting a Hash
Hash Methods
5. Loops and Iterators
for Loops
Blocks and Block Parameters
Iterating upto and downto
Multiple Iterator Arguments
while Loops
while Modifiers
Ensuring a while Loop Executes at Least Once
until Loops
loop
6. Conditional Statements
if..then..else
and, or, and not
Negation
if..elsif
unless
if and unless Modifiers
Case Statements
The === Method
Alternative Case Syntax
7. Methods
Class Methods
What Are Class Methods For?
Class Variables
Ruby Constructors: new or initialize?
Singleton Methods
Singleton Classes
Overriding Methods
Public, Protected, and Private Methods
8. Passing Arguments and Returning Values
Summarizing Instance, Class, and Singleton Methods
Returning Values
Returning Multiple Values
Default and Multiple Arguments
Assignment and Parameter Passing
Integers Are Special
The One-Way-In, One-Way-Out Principle
Modifying Receivers and Yielding New Objects
Potential Side Effects of Reliance on Argument Values
Parallel Assignment
9. Exception Handling
rescue: Execute Code When Error Occurs
ensure: Execute Code Whether or Not an Error Occurs
else: Execute Code When No Error Occurs
Error Numbers
retry: Attempt to Execute Code Again After an Error
raise: Reactivate a Handled Error
10. Blocks, Procs, and Lambdas
What Is a Block?
Line Breaks Are Significant
Nameless Functions
Look Familiar?
Blocks and Arrays
Procs and Lambdas
Block or Hash?
Creating Objects from Blocks
What Is a Closure?
yield
Blocks Within Blocks
Passing Named Proc Arguments
Precedence Rules
Blocks as Iterators
11. Symbols
Symbols and Strings
Symbols and Variables
Why Use Symbols?
12. Modules and Mixins
A Module Is Like a Class . . .
Module Methods
Modules as Namespaces
Included Modules, or “Mixins”
Name Conflicts
Alias Methods
Mix In with Care!
Including Modules from Files
13. Files and IO
Opening and Closing Files
Characters and Compatibility
Files and Directories
Copying Files
Directory Inquiries
A Discursion into Recursion
Sorting by Size
14. YAML
Converting to YAML
Nested Sequences
Saving YAML Data
Omitting Variables on Saving
Multiple Documents, One File
A YAML Database
Adventures in YAML
15. Marshal
Saving and Loading Data
Omitting Variables on Saving
Saving Singletons
YAML and Singletons
Marshal and Singletons
16. Regular Expressions
Making Matches
Match Groups
MatchData
Prematch and Postmatch
Greedy Matching
String Methods
File Operations
17. Threads
Creating Threads
Running Threads
Going Native
The Main Thread
Thread Status
Ensuring That a Thread Executes
Thread Priorities
The Main Thread Priority
Mutexes
Fibers
18. Debugging and Testing
IRB: Interactive Ruby
Debugging
Unit Testing
19. Ruby on Rails
Installing Rails
Do It Yourself . . .
Or Use an “All-in-One” Installer
Model-View-Controller
A First Ruby on Rails Application
Create a Rails Application
Create a Controller
Anatomy of a Simple Rails Application
The Generate Controller Script Summarized
Create a View
Rails Tags
Let’s Make a Blog!
Create the Database
Creating a MySQL Database
Scaffolding
Migration
Partials
Test It!
20. Dynamic Programming
Self-Modifying Programs
eval
Special Types of eval
Adding Variables and Methods
Creating Classes at Runtime
Bindings
send
Removing Methods
Handling Missing Methods
Writing Programs at Runtime
Exploring Further
A. Documenting Ruby with RDoc
B. Installing MySQL for Ruby on Rails
Downloading MySQL
Installing MySQL
Configuring MySQL
Can’t Find the Database?
C. Further Reading
Books
Ebooks
Websites
D. Ruby and Rails Development Software
IDEs and Editors
Web Servers
Databases
Ruby Implementations
Index
About the Author
Colophon
E. Updates
← Prev
Back
Next →
← Prev
Back
Next →