Kevin C. Baird received his Ph.D. from the State University of New York at Buffalo. He originally wrote his dissertation in Python but rewrote the project after discovering Ruby, and he hasn't looked back since. He has presented at RubyConf and written articles for Linux Journal, Music & Computers magazine, and the New Interfaces for Musical Expression conference proceedings.
Acknowledgments | p. xvii |
Introduction: What is Ruby? | p. xix |
Acquiring and Configuring Ruby | p. xx |
On a Unix or Unix-like System | p. xx |
On a Windows System | p. xxi |
Motivations for the Book | p. xxi |
Conventions | p. xxii |
Summary of Chapters | p. xxii |
Interactive Ruby and the Ruby Environment | p. 1 |
Starting irb | p. 2 |
Using irb | p. 2 |
Expressions | p. 2 |
Everything Is an Object | p. 2 |
Integers, Fixnums, and Bignums | p. 3 |
Addition, Concatenation, and Exceptions | p. 4 |
Casting | p. 4 |
Arrays | p. 5 |
Booleans | p. 6 |
Flow Control | p. 6 |
Methods | p. 8 |
Variables | p. 9 |
Constants | p. 10 |
Using the Ruby Interpreter and Environment | p. 10 |
Amusements and Simple Utilities | p. 13 |
Is It Payday? (check_payday.rb) | p. 14 |
The Code | p. 14 |
How It Works | p. 14 |
The Results | p. 16 |
Random Signature Generator (random_sig.rb and random_sig-windows.rb) | p. 16 |
The Code | p. 16 |
How It Works | p. 16 |
Running the Script | p. 19 |
The Results | p. 19 |
Hacking the Script | p. 19 |
The 99 Bottles of Beer Song (99bottles.rb) | p. 20 |
The Code | p. 20 |
How It Works | p. 21 |
Running the Script | p. 25 |
The Results | p. 25 |
Sound File Player (shuffle_play.rb) | p. 25 |
The Code | p. 26 |
How It Works | p. 27 |
Running the Script | p. 29 |
The Results | p. 29 |
Hacking the Script | p. 30 |
Chapter Recap | p. 31 |
Programmer Utilities | p. 33 |
What Is Truth? (boolean_golf.rb) | p. 33 |
The Code | p. 34 |
How It Works | p. 34 |
Hacking the Script | p. 36 |
Running the Script | p. 36 |
The Results | p. 36 |
Making a List (array_join.rb) | p. 36 |
The Code | p. 37 |
How It Works | p. 37 |
Running the Script | p. 39 |
Hacking the Script | p. 39 |
Command-Line Interface (uses_cli.rb and simple_cli.rb) | p. 39 |
The Code | p. 40 |
How It Works | p. 42 |
Running the Script | p. 44 |
Hacking the Script | p. 45 |
Palindromes (palindrome.rb and palindrome2.rb) | p. 45 |
The Code | p. 45 |
How It Works | p. 46 |
Hacking the Script | p. 46 |
Running the Script | p. 47 |
The Results | p. 48 |
Chapter Recap | p. 49 |
Text Manipulation | p. 51 |
End-of-Line Conversion (dos2unix.rb) | p. 51 |
The Code | p. 52 |
How It Works | p. 52 |
Running the Script | p. 55 |
The Results | p. 56 |
Hacking the Script | p. 56 |
Showing Line Numbers (line_num.rb) | p. 57 |
The Code | p. 57 |
How It Works | p. 57 |
Running the Script | p. 58 |
The Results | p. 58 |
Wrapping Lines of Text (softwrap.rb) | p. 59 |
The Code | p. 59 |
Running the Script | p. 62 |
The Results | p. 62 |
Hacking the Script | p. 62 |
Counting Words in a File (word_count.rb) | p. 62 |
The Code | p. 63 |
How It Works | p. 64 |
Running the Script | p. 64 |
The Results | p. 64 |
Word Histogram (most_common_words.rb) | p. 65 |
The Code | p. 65 |
How It Works | p. 65 |
Running the Script | p. 67 |
The Results | p. 67 |
Hacking the Script | p. 67 |
Rotating Characters in a String (rotate.rb) | p. 68 |
The Code | p. 68 |
How It Works | p. 68 |
Running the Script | p. 69 |
The Results | p. 69 |
Chapter Recap | p. 70 |
Number Utilities | p. 71 |
Computing Powers (power_of.rb) | p. 72 |
The Code | p. 72 |
How It Works | p. 73 |
Running the Script | p. 74 |
The Results | p. 75 |
Adding Commas to Numbers (commify.rb) | p. 75 |
Inheritance | p. 75 |
Modules | p. 76 |
The Code | p. 76 |
How It Works | p. 78 |
Running the Script | p. 81 |
The Results | p. 81 |
Roman Numerals (roman_numeral.rb) | p. 81 |
The Code | p. 82 |
How It Works | p. 83 |
Running the Script | p. 86 |
The Results | p. 86 |
Hacking the Script | p. 87 |
Currency Conversion, Basic (currency_converter1.rb) | p. 87 |
The Code | p. 88 |
How It Works | p. 89 |
Running the Script | p. 90 |
The Results | p. 90 |
Hacking the Script | p. 90 |
Currency Conversion, Advanced (currency_converter2.rb) | p. 90 |
The Code | p. 91 |
How It Works | p. 93 |
Running the Script | p. 97 |
The Results | p. 97 |
Hacking the Script | p. 98 |
Chapter Recap | p. 98 |
Functionalism with Blocks and Procs | p. 99 |
Our First lambda (make_incrementer.rb) | p. 100 |
The Code | p. 100 |
How It Works | p. 101 |
The Results | p. 101 |
Using Procs for Filtering (matching_members.rb) | p. 102 |
The Code | p. 102 |
How It Works | p. 102 |
Running the Script | p. 103 |
The Results | p. 103 |
Using Procs for Compounded Filtering (matching_compound_members.rb) | p. 103 |
The Code | p. 104 |
How It Works | p. 105 |
The Results | p. 107 |
Hacking the Script | p. 108 |
Returning Procs as Values (return_proc.rb) | p. 108 |
The Code | p. 108 |
The Results | p. 109 |
How It Works | p. 109 |
Nesting lambdas | p. 111 |
The Code | p. 111 |
How It Works | p. 112 |
Procs for Text (willow_and_anya.rb) | p. 112 |
The Code | p. 112 |
How It Works | p. 115 |
Running the Script | p. 118 |
The Results | p. 118 |
Hacking the Script | p. 119 |
Chapter Recap | p. 119 |
Using, Optimizing, and Testing Functional Techniques | p. 121 |
Basic Factorials and Fibonaccis (factorial1.rb through fibonacci5.rb) | p. 122 |
The Code | p. 122 |
How It Works | p. 123 |
The Results | p. 123 |
Hacking the Script | p. 124 |
Benchmarking and Profiling (tests/test_opts.rb) | p. 128 |
Benchmarking | p. 128 |
The Code | p. 128 |
How It Works | p. 129 |
Running the Script | p. 130 |
The Results | p. 130 |
Profiling | p. 131 |
Hacking the Script | p. 132 |
Converting Temperatures (temperature_converter.rb) | p. 132 |
The Code | p. 132 |
How It Works | p. 134 |
The Results | p. 136 |
Hacking the Script | p. 136 |
Testing temperature_converter.rb (tests/test_temp_converter.rb) | p. 137 |
The Code | p. 137 |
The Results | p. 138 |
How It Works | p. 139 |
Hacking the Script | p. 139 |
Chapter Recap | p. 140 |
HTML and XML Tools | p. 141 |
Cleaning Up HTML (html_tidy.rb) | p. 141 |
The Code | p. 142 |
How It Works | p. 144 |
Running the Script | p. 146 |
The Results | p. 147 |
Hacking the Script | p. 148 |
Counting Tags (xml_tag_counter.rb) | p. 148 |
The Code | p. 149 |
How It Works | p. 150 |
Running the Script | p. 153 |
The Results | p. 153 |
Hacking the Script | p. 153 |
Extracting Text from XML (xml_text_extractor.rb) | p. 154 |
The Code | p. 154 |
How It Works | p. 155 |
Running the Script | p. 155 |
The Results | p. 155 |
Hacking the Script | p. 156 |
Validating XML (xml_well_formedness_checker.rb) | p. 156 |
The Code | p. 156 |
How It Works | p. 157 |
Running the Script | p. 158 |
The Results | p. 158 |
Hacking the Script | p. 158 |
Chapter Recap | p. 159 |
More Complex Utilities and Tricks, Part I | p. 161 |
Finding Codes in the Bible or Moby-Dick (els_parser.rb) | p. 161 |
The Code | p. 162 |
How It Works | p. 164 |
Running the Script | p. 167 |
The Results | p. 167 |
Hacking the Script | p. 168 |
Mutating Strings into Weasels (methinks.rb) | p. 168 |
The Code | p. 168 |
How It Works | p. 171 |
Running the Script | p. 174 |
The Results | p. 174 |
Hacking the Script | p. 175 |
Mutating the Mutation of Strings into Weasels (methinks_meta.rb) | p. 176 |
The Code | p. 177 |
How It Works | p. 179 |
Running the Script | p. 181 |
The Results | p. 181 |
Hacking the Script | p. 182 |
Chapter Recap | p. 183 |
More Complex Utilities and Tricks, Part II | p. 185 |
Overnight DJ (radio_playerl.rb) | p. 186 |
The Code | p. 186 |
How It Works | p. 187 |
The Results | p. 189 |
Hacking the Script | p. 190 |
Better Overnight DJ (radio_player2.rb) | p. 190 |
The Code | p. 190 |
How It Works | p. 191 |
The Results | p. 192 |
Hacking the Script | p. 193 |
Numbers by Name (to_lang.rb) | p. 193 |
The Code | p. 194 |
How It Works | p. 198 |
The Results | p. 201 |
Hacking the Script | p. 202 |
Elegant Maps and Injects (symbol.rb) | p. 203 |
The Code | p. 203 |
How It Works | p. 203 |
The Results | p. 204 |
Hacking the Script | p. 204 |
Chapter Recap | p. 204 |
CGI and the Web | p. 205 |
Common Gateway Interface | p. 206 |
Preparation and Installation | p. 206 |
A Simple CGI Script (simple_cgi.rb) | p. 207 |
The Code | p. 207 |
How It Works | p. 208 |
The Results | p. 210 |
Hacking the Script | p. 210 |
Mod Ruby (mod_ruby_demo.rhtml and mod_ruby_demo.conf) | p. 211 |
The Code | p. 211 |
How It Works | p. 213 |
The Results | p. 214 |
Hacking the Script | p. 214 |
CSS Stylesheets, Part I (stylesheet.rcss) | p. 215 |
The Code | p. 215 |
How It Works | p. 216 |
The Results | p. 217 |
Hacking the Script | p. 218 |
CSS Stylesheets, Part II (stylesheet2.rcss) | p. 218 |
The Code | p. 218 |
How It Works | p. 220 |
The Results | p. 220 |
Hacking the Script | p. 221 |
Chapter Recap | p. 221 |
Rubygems and Rails Preparation | p. 223 |
RubyGems | p. 223 |
Installing RubyGems | p. 224 |
Using RubyGems | p. 224 |
Rails Preparation | p. 227 |
What Is Rails? | p. 228 |
Other Options for Installing Rails | p. 228 |
Databases | p. 229 |
The Structure of a Rails Application | p. 229 |
Chapter Recap | p. 235 |
A Simple Rails Project | p. 237 |
Creating the Application | p. 237 |
Initial Creation | p. 238 |
Preparing the Database | p. 238 |
Adding Data | p. 238 |
Creating the Model and Controllers | p. 240 |
Dissecting the Application | p. 241 |
Dissecting the Photo Model | p. 241 |
Dissecting the Controllers | p. 242 |
Dissecting the Helpers | p. 245 |
Dissecting the Album Controller's Views | p. 251 |
Dissecting the Feed Controller's images View | p. 254 |
Dissecting the Album Controller's Layout | p. 256 |
Using CSS | p. 257 |
Using the Application | p. 257 |
Learning More About Rails | p. 260 |
Chapter Recap | p. 260 |
How does Ruby Compare to Other Languages? | p. 261 |
C | p. 261 |
Haskell | p. 262 |
Java | p. 262 |
Lisp | p. 263 |
Perl | p. 264 |
PHP | p. 264 |
Python | p. 265 |
Smalltalk | p. 265 |
Summary of Ruby vs. Other Languages | p. 266 |
Index | p. 267 |
Table of Contents provided by Ingram. All Rights Reserved. |
The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.
The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.