Ruby Cookbook: Recipes for Object-Oriented Scripting
无水印，数字版，英文原版，有目录。 Ruby Cookbook: Recipes for Object-Oriented Scripting Why spend time on coding problems that others have already solved when you could be making real progress on your Ruby project? This updated cookbook provides more than 350 recipes for solving common problems, on topics ranging f
SECOND EDITION Ruby cookbook Lucas Carlson and leonard richardson Beng. Cambridge. Farnham·Kn· Sebastopol, Tokyo OREILLY° Ruby〔 bokbok by Lucas Carlson and Leonard Richardson Copyright C 2015 Lucas Carlson and Leonard Richardson. All rights reserved Printed in the United states of america Published by O reilly Media, Inc, 1005 Gravenstein Highway North, Sebastopol, CA95472 OReilly books may be purchased for educational, business, or sales promotional use. Online editions are alsoavailableformosttitles(http://safaribooksonline.com).Formoreinformationcontactourcorporate firstname.lastname@example.org Editors: Brian Anderson and Allyson MacDonald Interior Designer: David Futato Production editor: Matthew hacker Cover Designer: Ellie Volckhausen Proofreader: Rachel Monaghan Illustrator: rebecca demarest Indexer: Angela Howard July 2006 First edition March 2015 Second edition Revision history for the Second edition 2015-03-10: First release Seehttp://oreilly.com/catalog/errata.csp?isbn=9781449373719forreleasedetails The O Reilly logo is a registered trademark of O Reilly Media, Inc. Ruby Cookbook, the cover image of a side-striped jackal, and related trade dress are trademarks of O Reilly media, Inc While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/ or rights 978-1-449-37371-9 For Yoscelina, my muse and inspiration for everything great I have ever accomplished For Hugh and Valentina, the most incredible miracles ever. For Tess, who sat by me the whole time Lucas carlson For sumana eonard richardson Table of contents Preface, 1. ruby 2.1 1. 1 What's Different Between Ruby 1.8 and 2.1? 1.2 YARV(Yet Another Ruby vM) Bytecode Interpreter 1. 3 Syntax Changes 11 1.4 Keyword arguments 14 1.5 Performance Enhancements 15 1.6 Refinements 16 1.7 Debugging with DTrace and TracePoint 17 1.8 Module Prepending 19 1.9 New Methods 21 1. 10 New Classes 1.11 New Standard libraries 26 1.12 What's Next? 2. Strings. 29 2.1 Building a String from Parts 33 2.2 Substituting Variables into String 35 2.3 Substituting Variables into an Existing String 37 2. 4 Reversing a String by Words or Characters 9 2.5 Representing Unprintable Characters 2.6 Converting Between Characters and values 43 2.7 Converting Between Strings and Symbols 2. 8 Processing a String One Character at a Time 2.9 Processing a String One Word at a Time 2.10 Changing the Case of a String 2.11 Managing Whitespace 50 2.12 Testing Whether an Object Is String-Like 52 2. 13 Getting the Parts of a String You Want 53 2. 14 Word-Wrapping Lines of Text 54 2.15 Generating a Succession of Strings 2.16 Matching Strings with Regular Expressions 59 2. 17 Replacing Multiple Patterns in a Single Pass 61 2.18 Validating an Email address 63 2.19 Classifying Text with a Bayesian Analyzer 66 3. Numbers 69 3. 1 Parsing a Number from a String 3. 2 Comparing Floating-Point Numbers 73 3. 3 Representing Numbers to arbitrary Precision 3.4 Representing rational numbers 79 3.5 Generating Random Numbers 3.6 Converting between Numeric Bases 82 3.7 Taking logarithms 83 3.8 Finding Mean, Median, and Mode 86 3.9 Converting Between Degrees and Radians 89 3. 10 Multiplying Matrices 90 3. 11 Solving a System of linear equations 94 3. 12 USing Complex Numbers 3. 13 Simulating a Subclass of Fixnum 99 3. 14 Doing Math with Roman Numbers 103 3. 15 Generating a Sequence of numbers 109 3. 16 Generating Prime Numbers 3. 17 Checking a Credit Card Checksum 116 4. Date and 4. 1 Finding Today's Date 122 4.2 Parsing Dates, Precisely or Fuzzily 126 4.3 Printing a Date 129 4.4 Iterating Over dates 134 4.5 Doing Date Arithmetic 135 4.6 Counting the Days Since an Arbitrary Date 138 4.7 Converting Between Time Zones 140 4.8 Checking Whether Daylight Saving Time Is in Effect 142 4.9 Converting Between Time and Date Time Objects 4.10 Finding the Day of the Week 147 4.11 Handling Commercial Dates 149 4.12 Running a Code block periodically 150 4.13 Waiting a Certain Amount of Time 152 Table of contents 4. 14 Adding a Timeout to a long-Running Operation 155 5. Arrays.......... 157 5.1 Iterating Over an Array 159 5.2 Rearranging Values Without Using Temporary variables 163 5.3 Stripping Duplicate Elements from an Array 165 5.4 Reversing an array 166 5.5 Sorting an array 167 5.6 Ignoring Case When Sorting Strings 169 5. 7 Making Sure a Sorted Array Stays Sorted 170 5.8 Summing the Items of an Array 175 5.9 Sorting an Array by Frequency of Appearance 177 5.10 Shuffling an Array 179 5.11 Getting the N smallest Items of an Array 180 5.12 Building a Hash from an Array 183 5.13 Extracting Portions of Arrays 185 5.14 Computing Set Operations on Arrays 188 5. 15 Partitioning or Classifying a Set 191 6.Hashe.197 6.1 Using Symbols as Hash Ke 200 6.2 Creating a Hash with a Default value 201 6.3 Adding Elements to a Hash 203 6.4 Removing elements from a hash 205 6.5 USing an Array or Other Modifiable Object as a Hash Key 206 6.6 Keeping Multiple Values for the Same Hash Key 209 6.7 Iterating Over a hash 210 6.8 Iterating Over a Hash in Insertion Order 213 6.9 Printing a Hash 214 6.10 Inverting a Hash 216 6. 11 Choosing Randomly from a Weighted List 217 6.12 Building a Histogram 220 6.13 Remapping the Keys and Values of a Hash 222 6.14 Extracting Portions of Hashes 223 6.15 Searching a Hash with Regular Expressions 224 7. Files and directories ,227 7. 1 Checking to See If a File exists 230 7. 2 Checking Your Access to a file 232 7.3 Changing the Permissions on a File 234 7.4 Seeing When a File Was last Used 237 7.5 Listing a Directory 239 Table of contents|ⅶi 7.6 Reading the Contents of a File 242 7.7 Writing to a File 246 7.8 Writing to a Temporary file 247 7.9 Picking a Random Line from a file 249 7.10 Comparing Two Files 250 7. 11 Performing Random Access on Read-Once Input Streams 254 7. 12 Walking a Directory Tree 256 7. 13 Locking a File 259 7.14 Backing Up to Versioned Filenames 262 7.15 Pretending a String Is a file 265 7. 16 Redirecting Standard Input or Output 268 7. 17 Processing a Binary file 270 7.18 Deleting a File 274 7.19 Truncating a File 275 7. 20 Finding the Files You Want 277 7.21 Finding and Changing the Current Working Directory 279 8. Code blocks and iteration 281 8. 1 Creating and Invoking a block 284 8.2 Writing a Method That Accepts a block 286 8.3 Binding a block argument to a variable 289 8.4 Blocks as Closures: Using Outside Variables Within a Code Block 291 8.5 Writing an Iterator Over a Data Structure 293 8.6 Changing the Way an Object Iterates 296 8.7 Writing block methods That Classify or Collect 298 8.8 Stopping an Iteratic 300 8.9 Looping Through multiple Iterables in Parallel 302 8. 10 Hiding Setup and cleanup in a block method 306 8. 11 Coupling Systems Loosely with Callbacks 308 9. Objects and classes 9.1 Managing Instance Data 316 9.2 Managing Class Data 318 9.3 Checking Class or Module Membership 321 9.4 Writing an Inherited Class 323 9.5 Overloading methods 326 9.6 Validating and Modifying Attribute values 328 9.7 Defining a Virtual Attribute 330 9. 8 Delegating Method Calls to Another Object 331 9.9 Converting and Coercing Objects to Different Types 334 9.10 Getting a Human- Readable Printout of Any object 339 9.11 Accepting or Passing a Variable Number of Arguments 341 I Table of Contents
Scala Cookbook: Recipes for Object-Oriented and Functional Programming, 20132013-10-05
Scala Cookbook: Recipes for Object-Oriented and Functional Programming, 2013, 英文原版 by Alvin Alexander http://www.amazon.com/Scala-Cookbook-Object-Oriented-Functional-Programming/dp/1449339611
NGINX Cookbook: Advanced Recipes for High Performance Load Balancing2019-04-15
作者: Derek DeJonghe Pub Date: 2019 ISBN: 9781491968932 Pages: 175 Language: English Format: PDF
This is a cookbook of problem-solving recipes about Scala, the most interesting pro‐ gramming language I’ve ever used. The book contains solutions to more than 250 com‐ mon problems, shown with ...
VMware cookbook: A Real-World Guide to Effective VMware Use2011-10-26
In addition to the recipes, VMware Cookbook includes background information to help you determine your virtualization needs. You'll come to view VMware as part of the real environment, alongside ...
Linux Shell Scripting Cookbook - Third Edition2017-11-01
to-follow recipes on new features on Linux, particularly, Debian-based, to help you accomplish even the most complex tasks with ease, Who This Book Is For, If you are a beginner or an intermediate ...
Android Cookbook: Problems and Solutions for Android Developers2017-05-11
The second edition of this acclaimed cookbook includes recipes for working with user interfaces, multitouch gestures, location awareness, web services, and specific device features such as the phone,...
Raspberry Pi Cookbook: Software and Hardware Problems and Solutions_2nd Edition2018-06-17
The second edition of this popular cookbook provides more than 240 hands-on recipes for running this tiny low-cost computer with Linux, programming it with Python, and hooking up sensors, motors, and...
Deep Learning Cookbook_ practical recipes to get started quickly2018-07-30
With the recipes in this cookbook, you'll learn how to solve deep-learning problems for classifying and generating text, images, and music. Each chapter consists of several recipes needed to complete...
Qt5 C++ GUI Programming Cookbook PDF+源码2018-03-04
Qt5 C++ GUI Programming Cookbook 英文原版PDF及对应的源代码。来源于网络。如有侵权，告知后删除。
MySQL 8 Cookbook2018-04-27
MySQL 8 Cookbook: Over 150 recipes for high-performance database querying and administration Design and administer enterprise-grade MySQL 8 solutions MySQL is one of the most popular and widely used ...
He wrote the Ionic Cookbook (for more information, visit https://www.amazon.com/Ionic-Cookbook-Hoc-Phan/dp/1785287974), which was very well received. He has worked for both start-ups and large ...
Android Cookbook: Problems and Solutions for Android Developers, 2nd Edition2016-10-17
Android Cookbook: Problems and Solutions for Android Developers, 2nd Edition English | ISBN: 1449374433, 144937445X | 2016 | This cookbook doesn't just teach you how to build Android apps; it also ...
Unreal Engine 4 Scripting with C++ Cookbook pdf 0分2016-10-31
Unreal Engine 4 Scripting with C++ Cookbook 英文pdf
Android Application Development Cookbook: 93 Recipes for Building Winning Apps2013-11-07
A must-have collection of ready-to-use Android recipes! The popularity of Google Android devices is seemingly unstoppable and the Android 4 release offers, for the first time, a single OS solution for...
U3D NGUI 2020.1.5.zip
U3D NGUI 2020.1.5.zip