- ホーム
- > 洋書
- > 英文書
- > Computer / Languages
Full Description
Ruby PhrasebookJason ClintonEssential Code and CommandsRuby Phrasebook gives you the code you need to quickly and effectively work with Ruby, one of the fastest-growing languages in the world thanks to popular new Ruby technologies like Ruby on Rails.Concise and AccessibleEasy to carry and easy to use-lets you ditch all those bulky books for one portable pocket guideFlexible and FunctionalPacked with more than 100 customizable code snippets-so you can readily code functional Ruby in just about any situationJason Clinton uses Ruby daily in system administration and development for Advanced Clustering Technologies, a Linux Beowulf cluster integrator. He has been working in the computer industry for more than a decade and is actively involved in the Kansas City Ruby Users Group (KCRUG), serving as administrator of the group's web site and mailing list. Register your book at informit.com/register for convenient access to downloads, updates, and corrections as they become available.Programming / Ruby
Contents
Introduction 1 Audience 1How to Use This Book 2Conventions 2Acknowledgments 41 Converting Between Types 5Number from a String 6Number to Formatted String 7String to Array and Back Again 10String to Regular Expression and Back Again 12Array to Hash and Back Again 13Array to Set and Back Again 15Floating-Point, Integer, and Rational Numbers 152 Working with Strings 19Searching Strings 20Searching Strings with Regular Expressions 21Replacing Substrings 23Replacing Substrings using SprintF 24Replacing Substrings using Regu 26Working with Unicode 26Sanitizing Input 27Working with Line Endings 28Processing Large Strings 30Comparing Strings 31Checksumming a String (MD5 or Otherwise) 31Encrypting a String 323 Working with Collections 35Slicing an Array 35Iterating over an Array 37Creating Enumerable Classes 38Sorting an Array 40Iterating over Nested Arrays 41Modifying All the Values in an Array 42Sorting Nested Arrays 42Building a Hash from a Config File 44Sorting a Hash by Key or Value 45Eliminating Duplicate Data from Arrays (Sets) 46Working with Nested Sets 474 Working with Objects 49Inspecting Objects and Classes 50String Presentation of Objects 50Ruby-Style Polymorphisms ("Duck Typing") 51Comparing Objects 52Serializing Objects 53Duplication 54Protecting an Object Instance 55Garbage Collecting 56Using Symbols 575 Working with Pipes 61Determining Interactive Standard Pipes 62Synchronizing STDERR with STDOUT 63Capturing the Output of a Child Process 64Implementing a Progress Bar 65Creating a Secured Password Prompt 666 Working with Files 69Opening and Closing Files 69Searching and Seeking Large File Contents 70When to Use Binary Mode (Win32) 73Obtaining an Exclusive Lock 74Copying, Moving, and Deleting Files 747 Manipulating Text 77Parsing an LDIF 77Parsing a Simple Config File 78Interpolating One Text File 79Sorting the Contents of a File 80Processing a passwd File 818 Ruby One-Liners 83Simple Search 84Counting Lines in a File 84Head or Tail of a File 84MD5 or SHA1 Hash 85Simple HTTP Fetch 86Simple TCP Connect 87Escaping HTML 87Deleting Empty Directories 88Adding Users from a Text File 88Delete All the Files Just Extracted 899 Processing XML 91Opening an XML File 92Accessing an Element (Node) 93Getting a List of Attributes 95Adding an Element 96Changing an Element's Enclosed Text 97Deleting an Element 98Adding an Attribute 98Changing an Attribute 99Deleting an Attribute 99Escaping Characters for XML 100Transforming Using XSLT 100Validating Your XML 102A Simple RSS Parser 10310 Rapid Applications Development with GUIToolkits 107A Simple GTK+ Hello World 108Using Glade 110A Simple Qt Hello World 115Attaching a Signal Handler to a QtWidget Slot 116Using Qt Designer 118Attaching Signal Handlers to Qt DesignerGenerated Code 12411 Simple CGI Forms 127Processing a Web Form 128Returning Tabled Results 131Escaping Input 134Locking Down Ruby 136Receiving an Uploaded File 137Representing Data Graphically 13812 Connecting to Databases 143Opening (and Closing) a MySQL DatabaseConnection 144Creating a Table 145Getting a List of Tables 146Adding Rows to a Table 146Iterating Over Queried Rows 147Deleting Rows 147Deleting a Table 14813 Working with Networking and Sockets 151Connecting to a TCP Socket 152Running a TCP Server on a Socket 153Serializing Objects with YAML 156Network Objects with Distributed Ruby 158Using Net::HTTP 159Using Webrick 16014 Working with Threads 163Creating a Thread 164Using a Timer 165Killing a Thread 168Synchronizing Thread Communication 169Multithreaded Exception Gathering 17215 Documenting Your Ruby 175Documenting Ruby Code 176Typographic Conventions Used 177Overriding Method Signatures inDocumentation 179Hiding a Module, Class, or Method 180Providing Program Usage Help 180Generating HTML Documentation 182Generating and Installing Documentation for ri 18316 Working with Ruby Packages 185Installing a Module 187Removing a Module 188Searching for a Module 188Updating Modules 188Examining a Module 189Packaging Your Module with Hoe 189Creating a Simple Test Case 190Distributing Your Module on RubyForge 191Making Rakefile Standalone 192Index 195