did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

We're the #1 textbook rental company. Let us show you why.

9781593271480

Ruby by Example

by
  • ISBN13:

    9781593271480

  • ISBN10:

    1593271484

  • Format: Trade Paper
  • Copyright: 2007-06-01
  • Publisher: No Starch Press
  • Purchase Benefits
  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $29.95

Summary

There may be no better way to learn how to program than by dissecting real, representative examples written in your language of choice. Ruby by Example analyzes a series of Ruby scripts, examining how the code works, explaining the concepts it illustrates, and showing how to modify it to suit your needs. Baird's examples demonstrate key features of the language (such as inheritance, encapsulation, higher-order functions, and recursion), while simultaneously solving difficult problems (such as validating XML, creating a bilingual program, and creating command-line interfaces). Each chapter builds upon the previous, and each key concept is highlighted in the margin to make it easier for you to navigate the book.

Author Biography

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.

Table of Contents

Acknowledgmentsp. xvii
Introduction: What is Ruby?p. xix
Acquiring and Configuring Rubyp. xx
On a Unix or Unix-like Systemp. xx
On a Windows Systemp. xxi
Motivations for the Bookp. xxi
Conventionsp. xxii
Summary of Chaptersp. xxii
Interactive Ruby and the Ruby Environmentp. 1
Starting irbp. 2
Using irbp. 2
Expressionsp. 2
Everything Is an Objectp. 2
Integers, Fixnums, and Bignumsp. 3
Addition, Concatenation, and Exceptionsp. 4
Castingp. 4
Arraysp. 5
Booleansp. 6
Flow Controlp. 6
Methodsp. 8
Variablesp. 9
Constantsp. 10
Using the Ruby Interpreter and Environmentp. 10
Amusements and Simple Utilitiesp. 13
Is It Payday? (check_payday.rb)p. 14
The Codep. 14
How It Worksp. 14
The Resultsp. 16
Random Signature Generator (random_sig.rb and random_sig-windows.rb)p. 16
The Codep. 16
How It Worksp. 16
Running the Scriptp. 19
The Resultsp. 19
Hacking the Scriptp. 19
The 99 Bottles of Beer Song (99bottles.rb)p. 20
The Codep. 20
How It Worksp. 21
Running the Scriptp. 25
The Resultsp. 25
Sound File Player (shuffle_play.rb)p. 25
The Codep. 26
How It Worksp. 27
Running the Scriptp. 29
The Resultsp. 29
Hacking the Scriptp. 30
Chapter Recapp. 31
Programmer Utilitiesp. 33
What Is Truth? (boolean_golf.rb)p. 33
The Codep. 34
How It Worksp. 34
Hacking the Scriptp. 36
Running the Scriptp. 36
The Resultsp. 36
Making a List (array_join.rb)p. 36
The Codep. 37
How It Worksp. 37
Running the Scriptp. 39
Hacking the Scriptp. 39
Command-Line Interface (uses_cli.rb and simple_cli.rb)p. 39
The Codep. 40
How It Worksp. 42
Running the Scriptp. 44
Hacking the Scriptp. 45
Palindromes (palindrome.rb and palindrome2.rb)p. 45
The Codep. 45
How It Worksp. 46
Hacking the Scriptp. 46
Running the Scriptp. 47
The Resultsp. 48
Chapter Recapp. 49
Text Manipulationp. 51
End-of-Line Conversion (dos2unix.rb)p. 51
The Codep. 52
How It Worksp. 52
Running the Scriptp. 55
The Resultsp. 56
Hacking the Scriptp. 56
Showing Line Numbers (line_num.rb)p. 57
The Codep. 57
How It Worksp. 57
Running the Scriptp. 58
The Resultsp. 58
Wrapping Lines of Text (softwrap.rb)p. 59
The Codep. 59
Running the Scriptp. 62
The Resultsp. 62
Hacking the Scriptp. 62
Counting Words in a File (word_count.rb)p. 62
The Codep. 63
How It Worksp. 64
Running the Scriptp. 64
The Resultsp. 64
Word Histogram (most_common_words.rb)p. 65
The Codep. 65
How It Worksp. 65
Running the Scriptp. 67
The Resultsp. 67
Hacking the Scriptp. 67
Rotating Characters in a String (rotate.rb)p. 68
The Codep. 68
How It Worksp. 68
Running the Scriptp. 69
The Resultsp. 69
Chapter Recapp. 70
Number Utilitiesp. 71
Computing Powers (power_of.rb)p. 72
The Codep. 72
How It Worksp. 73
Running the Scriptp. 74
The Resultsp. 75
Adding Commas to Numbers (commify.rb)p. 75
Inheritancep. 75
Modulesp. 76
The Codep. 76
How It Worksp. 78
Running the Scriptp. 81
The Resultsp. 81
Roman Numerals (roman_numeral.rb)p. 81
The Codep. 82
How It Worksp. 83
Running the Scriptp. 86
The Resultsp. 86
Hacking the Scriptp. 87
Currency Conversion, Basic (currency_converter1.rb)p. 87
The Codep. 88
How It Worksp. 89
Running the Scriptp. 90
The Resultsp. 90
Hacking the Scriptp. 90
Currency Conversion, Advanced (currency_converter2.rb)p. 90
The Codep. 91
How It Worksp. 93
Running the Scriptp. 97
The Resultsp. 97
Hacking the Scriptp. 98
Chapter Recapp. 98
Functionalism with Blocks and Procsp. 99
Our First lambda (make_incrementer.rb)p. 100
The Codep. 100
How It Worksp. 101
The Resultsp. 101
Using Procs for Filtering (matching_members.rb)p. 102
The Codep. 102
How It Worksp. 102
Running the Scriptp. 103
The Resultsp. 103
Using Procs for Compounded Filtering (matching_compound_members.rb)p. 103
The Codep. 104
How It Worksp. 105
The Resultsp. 107
Hacking the Scriptp. 108
Returning Procs as Values (return_proc.rb)p. 108
The Codep. 108
The Resultsp. 109
How It Worksp. 109
Nesting lambdasp. 111
The Codep. 111
How It Worksp. 112
Procs for Text (willow_and_anya.rb)p. 112
The Codep. 112
How It Worksp. 115
Running the Scriptp. 118
The Resultsp. 118
Hacking the Scriptp. 119
Chapter Recapp. 119
Using, Optimizing, and Testing Functional Techniquesp. 121
Basic Factorials and Fibonaccis (factorial1.rb through fibonacci5.rb)p. 122
The Codep. 122
How It Worksp. 123
The Resultsp. 123
Hacking the Scriptp. 124
Benchmarking and Profiling (tests/test_opts.rb)p. 128
Benchmarkingp. 128
The Codep. 128
How It Worksp. 129
Running the Scriptp. 130
The Resultsp. 130
Profilingp. 131
Hacking the Scriptp. 132
Converting Temperatures (temperature_converter.rb)p. 132
The Codep. 132
How It Worksp. 134
The Resultsp. 136
Hacking the Scriptp. 136
Testing temperature_converter.rb (tests/test_temp_converter.rb)p. 137
The Codep. 137
The Resultsp. 138
How It Worksp. 139
Hacking the Scriptp. 139
Chapter Recapp. 140
HTML and XML Toolsp. 141
Cleaning Up HTML (html_tidy.rb)p. 141
The Codep. 142
How It Worksp. 144
Running the Scriptp. 146
The Resultsp. 147
Hacking the Scriptp. 148
Counting Tags (xml_tag_counter.rb)p. 148
The Codep. 149
How It Worksp. 150
Running the Scriptp. 153
The Resultsp. 153
Hacking the Scriptp. 153
Extracting Text from XML (xml_text_extractor.rb)p. 154
The Codep. 154
How It Worksp. 155
Running the Scriptp. 155
The Resultsp. 155
Hacking the Scriptp. 156
Validating XML (xml_well_formedness_checker.rb)p. 156
The Codep. 156
How It Worksp. 157
Running the Scriptp. 158
The Resultsp. 158
Hacking the Scriptp. 158
Chapter Recapp. 159
More Complex Utilities and Tricks, Part Ip. 161
Finding Codes in the Bible or Moby-Dick (els_parser.rb)p. 161
The Codep. 162
How It Worksp. 164
Running the Scriptp. 167
The Resultsp. 167
Hacking the Scriptp. 168
Mutating Strings into Weasels (methinks.rb)p. 168
The Codep. 168
How It Worksp. 171
Running the Scriptp. 174
The Resultsp. 174
Hacking the Scriptp. 175
Mutating the Mutation of Strings into Weasels (methinks_meta.rb)p. 176
The Codep. 177
How It Worksp. 179
Running the Scriptp. 181
The Resultsp. 181
Hacking the Scriptp. 182
Chapter Recapp. 183
More Complex Utilities and Tricks, Part IIp. 185
Overnight DJ (radio_playerl.rb)p. 186
The Codep. 186
How It Worksp. 187
The Resultsp. 189
Hacking the Scriptp. 190
Better Overnight DJ (radio_player2.rb)p. 190
The Codep. 190
How It Worksp. 191
The Resultsp. 192
Hacking the Scriptp. 193
Numbers by Name (to_lang.rb)p. 193
The Codep. 194
How It Worksp. 198
The Resultsp. 201
Hacking the Scriptp. 202
Elegant Maps and Injects (symbol.rb)p. 203
The Codep. 203
How It Worksp. 203
The Resultsp. 204
Hacking the Scriptp. 204
Chapter Recapp. 204
CGI and the Webp. 205
Common Gateway Interfacep. 206
Preparation and Installationp. 206
A Simple CGI Script (simple_cgi.rb)p. 207
The Codep. 207
How It Worksp. 208
The Resultsp. 210
Hacking the Scriptp. 210
Mod Ruby (mod_ruby_demo.rhtml and mod_ruby_demo.conf)p. 211
The Codep. 211
How It Worksp. 213
The Resultsp. 214
Hacking the Scriptp. 214
CSS Stylesheets, Part I (stylesheet.rcss)p. 215
The Codep. 215
How It Worksp. 216
The Resultsp. 217
Hacking the Scriptp. 218
CSS Stylesheets, Part II (stylesheet2.rcss)p. 218
The Codep. 218
How It Worksp. 220
The Resultsp. 220
Hacking the Scriptp. 221
Chapter Recapp. 221
Rubygems and Rails Preparationp. 223
RubyGemsp. 223
Installing RubyGemsp. 224
Using RubyGemsp. 224
Rails Preparationp. 227
What Is Rails?p. 228
Other Options for Installing Railsp. 228
Databasesp. 229
The Structure of a Rails Applicationp. 229
Chapter Recapp. 235
A Simple Rails Projectp. 237
Creating the Applicationp. 237
Initial Creationp. 238
Preparing the Databasep. 238
Adding Datap. 238
Creating the Model and Controllersp. 240
Dissecting the Applicationp. 241
Dissecting the Photo Modelp. 241
Dissecting the Controllersp. 242
Dissecting the Helpersp. 245
Dissecting the Album Controller's Viewsp. 251
Dissecting the Feed Controller's images Viewp. 254
Dissecting the Album Controller's Layoutp. 256
Using CSSp. 257
Using the Applicationp. 257
Learning More About Railsp. 260
Chapter Recapp. 260
How does Ruby Compare to Other Languages?p. 261
Cp. 261
Haskellp. 262
Javap. 262
Lispp. 263
Perlp. 264
PHPp. 264
Pythonp. 265
Smalltalkp. 265
Summary of Ruby vs. Other Languagesp. 266
Indexp. 267
Table of Contents provided by Ingram. All Rights Reserved.

Supplemental Materials

What is included with this book?

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.

Rewards Program