Baird Ruby by Example Concepts And Code
معرفی کتاب «Baird Ruby by Example Concepts And Code» نوشتهٔ Kevin C. Baird، منتشرشده توسط نشر No Starch Press در سال 2007. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است. «Baird Ruby by Example Concepts And Code» در دستهٔ بدون دستهبندی قرار دارد.
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. You'll learn how to: * Use the interactive Ruby shell (irb) to learn key features of the language * Extend Ruby using RubyGems, the Ruby package manager * Create numerical utilities, as well as utilities that process and analyze HTML/XML * Implement purely functional and metaprogramming techniques to save time and effort * Optimize, profile, and test your code to make sure that it not only does its job, but does it well * Create web applications using Rails Ruby is the fastest growing programming language today, and for good reason: Its elegant syntax and readable code make for prolific and happy programmers. But it can be difficult to understand and implement without a little help. Ruby by Example shows you how to take advantage of Ruby as you explore Ruby's fundamental concepts in action. RUBY BY EXAMPLE 1 Contents in Detail 11 Acknowledgments 19 Introduction: What Is Ruby? 21 Acquiring and Configuring Ruby 22 On a Unix or Unix-like System 22 On a Windows System 23 Motivations for the Book 23 Conventions 24 Summary of Chapters 24 1: Interactive Ruby and the Ruby Environment 27 Starting irb 28 Using irb 28 Expressions 28 Everything Is an Object 28 Integers, Fixnums, and Bignums 29 Addition, Concatenation, and Exceptions 30 Casting 30 Arrays 31 Booleans 32 Flow Control 32 Methods 34 Variables 35 Constants 36 Using the Ruby Interpreter and Environment 36 2: Amusements and Simple Utilities 39 #1 Is It Payday? (check_payday.rb) 40 The Code 40 How It Works 40 The Results 42 #2 Random Signature Generator (random_sig.rb and random_sig-windows.rb) 42 The Code 42 How It Works 42 Running the Script 45 The Results 45 Hacking the Script 45 #3 The 99 Bottles of Beer Song (99bottles.rb) 46 The Code 46 How It Works 47 Running the Script 51 The Results 51 #4 Sound File Player (shuffle_play.rb) 51 The Code 52 How It Works 53 Running the Script 55 The Results 55 Hacking the Script 56 Chapter Recap 57 3:Programmer Utilities 59 #5 What Is Truth? (boolean_golf.rb) 59 The Code 60 How It Works 60 Hacking the Script 62 Running the Script 62 The Results 62 #6 Making a List (array_join.rb) 62 The Code 63 How It Works 63 Running the Script 65 Hacking the Script 65 #7 Command-Line Interface (uses_cli.rb and simple_cli.rb) 65 The Code 66 How It Works 68 Running the Script 70 Hacking the Script 71 #8 Palindromes (palindrome.rb and palindrome2.rb) 71 The Code 71 How It Works 72 Hacking the Script 72 Running the Script 73 The Results 74 Chapter Recap 75 4: Text Manipulation 77 #9 End-of-Line Conversion (dos2unix.rb) 77 The Code 78 How It Works 78 Running the Script 81 The Results 82 Hacking the Script 82 #10 Showing Line Numbers (line_num.rb) 83 The Code 83 How It Works 83 Running the Script 84 The Results 84 #11 Wrapping Lines of Text (softwrap.rb) 85 The Code 85 Running the Script 88 The Results 88 Hacking the Script 88 #12 Counting Words in a File (word_count.rb) 88 The Code 89 How It Works 90 Running the Script 90 The Results 90 #13 Word Histogram (most_common_words.rb) 91 The Code 91 How It Works 91 Running the Script 93 The Results 93 Hacking the Script 93 #14 Rotating Characters in a String (rotate.rb) 94 The Code 94 How It Works 94 Running the Script 95 The Results 95 Chapter Recap 96 5: Number Utilities 97 #15 Computing Powers (power_of.rb) 98 The Code 98 How It Works 99 Running the Script 100 The Results 101 #16 Adding Commas to Numbers (commify.rb) 101 Inheritance 101 Modules 102 The Code 102 How It Works 104 Running the Script 107 The Results 107 #17 Roman Numerals (roman_numeral.rb) 107 The Code 108 How It Works 109 Running the Script 112 The Results 112 Hacking the Script 113 #18 Currency Conversion, Basic (currency_converter1.rb) 113 The Code 114 How It Works 115 Running the Script 116 The Results 116 Hacking the Script 116 #19 Currency Conversion, Advanced (currency_converter2.rb) 116 The Code 117 How It Works 119 Running the Script 123 The Results 123 Hacking the Script 124 Chapter Recap 124 6: Functionalism with Blocks and Procs 125 #20 Our First lambda (make_incrementer.rb) 126 The Code 126 How It Works 127 The Results 127 #21 Using Procs for Filtering (matching_members.rb) 128 The Code 128 How It Works 128 Running the Script 129 The Results 129 #22 Using Procs for Compounded Filtering (matching_compound_members.rb) 129 The Code 130 How It Works 131 The Results 133 Hacking the Script 134 #23 Returning Procs as Values (return_proc.rb) 134 The Code 134 The Results 135 How It Works 135 #24 Nesting lambdas 137 The Code 137 How It Works 138 #25 Procs for Text (willow_and_anya.rb) 138 The Code 138 How It Works 141 Running the Script 144 The Results 144 Hacking the Script 145 Chapter Recap 145 7: Using, Optimizing, and Testing Functional Techniques 147 #26 Basic Factorials and Fibonaccis (factorial1.rb through fibonacci5.rb) 148 The Code 148 How It Works 149 The Results 149 Hacking the Script 150 #27 Benchmarking and Profiling (tests/test_opts.rb) 154 Benchmarking 154 The Code 154 How It Works 155 Running the Script 156 The Results 156 Profiling 157 Hacking the Script 158 #28 Converting Temperatures (temperature_converter.rb) 158 The Code 158 How It Works 160 The Results 162 Hacking the Script 162 #29 Testing temperature_converter.rb (tests/ test_temp_converter.rb) 163 The Code 163 The Results 164 How It Works 165 Hacking the Script 165 Chapter Recap 166 8: HTML and XML Tools 167 #30 Cleaning Up HTML (html_tidy.rb) 167 The Code 168 How It Works 170 Running the Script 172 The Results 173 Hacking the Script 174 #31 Counting Tags (xml_tag_counter.rb) 174 The Code 175 How It Works 176 Running the Script 179 The Results 179 Hacking the Script 179 #32 Extracting Text from XML (xml_text_extractor.rb) 180 The Code 180 How It Works 181 Running the Script 181 The Results 181 Hacking the Script 182 #33 Validating XML (xml_well_formedness_checker.rb) 182 The Code 182 How It Works 183 Running the Script 184 The Results 184 Hacking the Script 184 Chapter Recap 185 9: More Complex Utilities and Tricks, Part I 187 #34 Finding Codes in the Bible or Moby-Dick (els_parser.rb) 187 The Code 188 How It Works 190 Running the Script 193 The Results 193 Hacking the Script 194 #35 Mutating Strings into Weasels (methinks.rb) 194 The Code 194 How It Works 197 Running the Script 200 The Results 200 Hacking the Script 201 #36 Mutating the Mutation of Strings into Weasels (methinks_meta.rb) 202 The Code 203 How It Works 205 Running the Script 207 The Results 207 Hacking the Script 208 Chapter Recap 209 10: More Complex Utilities and Tricks, Part II 211 #37 Overnight DJ (radio_player1.rb) 212 The Code 212 How It Works 213 The Results 215 Hacking the Script 216 #38 Better Overnight DJ (radio_player2.rb) 216 The Code 216 How It Works 217 The Results 218 Hacking the Script 219 #39 Numbers by Name (to_lang.rb) 219 The Code 220 How It Works 224 The Results 227 Hacking the Script 228 #40 Elegant Maps and Injects (symbol.rb) 229 The Code 229 How It Works 229 The Results 230 Hacking the Script 230 Chapter Recap 230 11: CGI and the Web 231 Common Gateway Interface 232 Preparation and Installation 232 #41 A Simple CGI Script (simple_cgi.rb) 233 The Code 233 How It Works 234 The Results 236 Hacking the Script 236 #42 Mod Ruby (mod_ruby_demo.rhtml and mod_ruby_demo.conf) 237 The Code 237 How It Works 239 The Results 240 Hacking the Script 240 #43 CSS Stylesheets, Part I (stylesheet.rcss) 241 The Code 241 How It Works 242 The Results 243 Hacking the Script 244 #44 CSS Stylesheets, Part II (stylesheet2.rcss) 244 The Code 244 How It Works 246 The Results 246 Hacking the Script 247 Chapter Recap 247 12: RubyGems and Rails Preparation 249 RubyGems 249 Installing RubyGems 250 Using RubyGems 250 Rails Preparation 253 What Is Rails? 254 Other Options for Installing Rails 254 Databases 255 The Structure of a Rails Application 255 Chapter Recap 261 13: A Simple Rails Project 263 Creating the Application 263 Initial Creation 264 Preparing the Database 264 Adding Data 264 Creating the Model and Controllers 266 Dissecting the Application 267 Dissecting the Photo Model 267 Dissecting the Controllers 268 Dissecting the Helpers 271 Dissecting the Album Controller’s Views 277 Dissecting the Feed Controller’s images View 280 Dissecting the Album Controller’s Layout 282 Using CSS 283 Using the Application 283 Learning More About Rails 286 Chapter Recap 286 How Does Ruby Compare to Other Languages? 287 C 287 Haskell 288 Java 288 Lisp 289 Perl 290 PHP 290 Python 291 Smalltalk 291 Summary of Ruby vs. Other Languages 292 Index 293
دانلود کتاب Baird Ruby by Example Concepts And Code