Ruby Phrasebook

Overview

Ruby Phrasebook

Jason Clinton

Essential Code and Commands

Ruby 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 ...

See more details below
Available through our Marketplace sellers and in stores.

Pick Up In Store Near You

Reserve and pick up in 60 minutes at your local store

Other sellers (Paperback)
  • All (11) from $1.99   
  • New (4) from $18.69   
  • Used (7) from $1.99   
Close
Sort by
Page 1 of 1
Showing All
Note: Marketplace items are not eligible for any BN.com coupons and promotions
$18.69
Seller since 2008

Feedback rating:

(17544)

Condition:

New — never opened or used in original packaging.

Like New — packaging may have been opened. A "Like New" item is suitable to give as a gift.

Very Good — may have minor signs of wear on packaging but item works perfectly and has no damage.

Good — item is in good condition but packaging may have signs of shelf wear/aging or torn packaging. All specific defects should be noted in the Comments section associated with each item.

Acceptable — item is in working order but may show signs of wear such as scratches or torn packaging. All specific defects should be noted in the Comments section associated with each item.

Used — An item that has been opened and may show signs of wear. All specific defects should be noted in the Comments section associated with each item.

Refurbished — A used item that has been renewed or updated and verified to be in proper working condition. Not necessarily completed by the original manufacturer.

New
Brand New, Perfect Condition, Please allow 4-14 business days for delivery. 100% Money Back Guarantee, Over 1,000,000 customers served.

Ships from: Westminster, MD

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
$18.70
Seller since 2007

Feedback rating:

(23362)

Condition: New
BRAND NEW

Ships from: Avenel, NJ

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
$40.00
Seller since 2010

Feedback rating:

(7)

Condition: New
8-25-08 other 1 BRAND NEW! ONLY Expedited orders are shipped with tracking number! *WE DO NOT SHIP TO PO BOX* Please allow up to 14 days delivery for order with standard ... shipping. SHIPPED FROM MULTIPLE LOCATIONS. Read more Show Less

Ships from: San Jose, CA

Usually ships in 1-2 business days

  • Canadian
  • Standard, 48 States
  • Standard (AK, HI)
  • Express, 48 States
  • Express (AK, HI)
$40.23
Seller since 2014

Feedback rating:

(2)

Condition: New
New

Ships from: Idyllwild, CA

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
  • Express, 48 States
  • Express (AK, HI)
Page 1 of 1
Showing All
Close
Sort by
Sending request ...

Overview

Ruby Phrasebook

Jason Clinton

Essential Code and Commands

Ruby 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 Accessible

Easy to carry and easy to use—lets you ditch all those bulky books for one portable pocket guide

Flexible and Functional

Packed with more than 100 customizable code snippets—so you can readily code functional Ruby in just about any situation

Jason 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

Read More Show Less

Product Details

  • ISBN-13: 9780672328978
  • Publisher: Addison-Wesley
  • Publication date: 9/8/2008
  • Series: Developer's Library Series
  • Pages: 204
  • Product dimensions: 4.40 (w) x 6.90 (h) x 0.50 (d)

Meet the Author

Jason Clinton has been working in the computerindustry for more than a decade. He is actively involved in the Kansas City Ruby Users Group (KCRUG), serving as administrator of the group’s website and mailing list, and he teaches a community class on Linux at University of Missouri-Kansas City.

Clinton uses Ruby daily in system administration and development for Advanced Clustering Technologies, a Linux Beowulf cluster integrator.

Read More Show Less

Read an Excerpt

IntroductionIntroductionAudience

You can find some great Ruby books on the market. If you are new to Ruby, a friend or someone on the Internet has probably already listed some favorite Ruby books—and you should buy those books. But every book has its niche: Each attempts to appeal to a certain need of a programmer.

It is my belief that the best thing this book can do for you is show you the code. I promise to keep the chat to a minimum, to focus instead on the quality and quantity of actual Ruby code. I'll also keep as much useful information in as tight a space as is possible.

Unlike any other book on the market at the time of this writing, this book is intended to be a (laptop-bag) "pocket-size" resource that enables you to quickly look up a topic and find examples of practical Ruby code—a topical quick reference, if you will. In each of the topics covered, I try to provide as thorough an approach to each task as the size allows for; there's not as much room for coverage of topical solutions as there is in much larger books with similar goals, such as The Ruby Way, 2nd Edition (Sams, 2006), by Hal Fulton. Because of this, other issues that are often given equal priority are relegated to second. For instance, this is not a tutorial; the code samples have some explanation, but I assume that you have a passing familiarity with the language. Also, when possible, I try to point out issues related to security and performance, but I make no claim that these are my highest priority.

I hope that you find this book a useful tool that you keep next to your keyboard whenever you are phrase-mongering inRuby.How to Use This Book

I have not intended for this book to be read cover to cover. Instead, you should place your bookmark at the Table of Contents so you can open the book, find the topic you are programming on at the moment, and go immediately to a description of all the issues you might run into.

The content in the book is arranged by topic instead of Ruby class. The benefit is that you can go to one place in this book instead of four or five areas in Ruby's own documentation. (Not that there's anything wrong with Ruby's documentation. It's just that sometimes you are working with several classes at a time and, because Ruby's docs are arranged by class, you have to jump around a lot.)Conventions

Phrases throughout the book are put in dark gray boxes at the beginning of every topic.

Phrases look like this.

Code snippets that appear in normal text are in italics. All other code blocks, samples, and output appear as follows:

# code sample boxes.

Parentheses are optional in Ruby in some cases—the rule is: you must have parentheses in your method call if you are calling another function in your list of parameters, or passing a literal code block to the method. In all other cases, parentheses are optional. Personally, I'm a sucker for consistency but one of the indisputable strengths of Ruby is the flexibility of the syntax.

In an attempt to have consistency between this book and others, I will (reluctantly) use .class_method() to refer to class methods, ::class_variable to refer to class variables, #method() to refer to instance methods, and finally #var to refer to instance variables. When referring to variables and methods which are members of the same class, I'll use the appropriate @variable and @@class_varriable.

I know that some people might find these two rules annoying—especially those coming from languages that use the '::' and '.' notation everywhere. In all practicality, you will never be so consistent—and rightfully so. One of Ruby's strengths is that there is a ton of flexibility. In fact, this flexibility has helped make Ruby on Rails so popular. This allowed the creators of Rails to make what appears to be a domain-specific language (a language well-suited for a specific kind of work) for web development. But really, all that is going on is a variation on Ruby syntax. And this is one of the many reasons that Ruby is more suitable for a given problem than, say, Python. Python's rigidity ("there should be one—and preferably only one—obvious way to do it") doesn't lend itself to DSL, so the programmers in that language are forced to use other means (which might or might not turn out to be unpleasant).

I always use single quotes (') in Ruby code unless I actually want to make use of the double-quote (")features (interpolation and substitution).

I always put the result of the evaluation of the statement (or block) on the next line with a proceeding #=>, similar to what you would find if you were using irb or browsing Ruby's documentation.

Comments on executable lines of code start with # and are in italics to the end of the comment. Comments on #=> lines are in parentheses and are in italics.Acknowledgments

Without the Pragmatic Programmers' freely available 1st Edition of Programming Ruby, I would have never discovered the wonderful world of Ruby. The Pickaxe books and the great Ruby community are what make projects like this one possible.

Thanks to my loving partner, Brandon S. Ward, for his infinite patience while working on this book.Reporting Errata

Readers will almost certainly find topics that they wish were covered which we were overlooked when planning this book. I encourage you to please contact us and let us know what you would like to see included in later editions. Criticisms are also welcome. Contact information can be found in the front-matter of this book.

© Copyright Pearson Education. All rights reserved.

Read More Show Less

Table of Contents

Introduction 1

Audience 1

How to Use This Book 2

Conventions 2

Acknowledgments 4

1 Converting Between Types 5

Number from a String 6

Number to Formatted String 7

String to Array and Back Again 10

String to Regular Expression and Back Again 12

Array to Hash and Back Again 13

Array to Set and Back Again 15

Floating-Point, Integer, and Rational Numbers 15

2 Working with Strings 19

Searching Strings 20

Searching Strings with Regular Expressions 21

Replacing Substrings 23

Replacing Substrings using SprintF 24

Replacing Substrings using Regu 26

Working with Unicode 26

Sanitizing Input 27

Working with Line Endings 28

Processing Large Strings 30

Comparing Strings 31

Checksumming a String (MD5 or Otherwise) 31

Encrypting a String 32

3 Working with Collections 35

Slicing an Array 35

Iterating over an Array 37

Creating Enumerable Classes 38

Sorting an Array 40

Iterating over Nested Arrays 41

Modifying All the Values in an Array 42

Sorting Nested Arrays 42

Building a Hash from a Config File 44

Sorting a Hash by Key or Value 45

Eliminating Duplicate Data from Arrays (Sets) 46

Working with Nested Sets 47

4 Working with Objects 49

Inspecting Objects and Classes 50

String Presentation of Objects 50

Ruby-Style Polymorphisms (“Duck Typing”) 51

Comparing Objects 52

Serializing Objects 53

Duplication 54

Protecting an Object Instance 55

Garbage Collecting 56

Using Symbols 57

5 Working with Pipes 61

Determining Interactive Standard Pipes 62

Synchronizing STDERR with STDOUT 63

Capturing the Output of a Child Process 64

Implementing a Progress Bar 65

Creating a Secured Password Prompt 66

6 Working with Files 69

Opening and Closing Files 69

Searching and Seeking Large File Contents 70

When to Use Binary Mode (Win32) 73

Obtaining an Exclusive Lock 74

Copying, Moving, and Deleting Files 74

7 Manipulating Text 77

Parsing an LDIF 77

Parsing a Simple Config File 78

Interpolating One Text File 79

Sorting the Contents of a File 80

Processing a passwd File 81

8 Ruby One-Liners 83

Simple Search 84

Counting Lines in a File 84

Head or Tail of a File 84

MD5 or SHA1 Hash 85

Simple HTTP Fetch 86

Simple TCP Connect 87

Escaping HTML 87

Deleting Empty Directories 88

Adding Users from a Text File 88

Delete All the Files Just Extracted 89

9 Processing XML 91

Opening an XML File 92

Accessing an Element (Node) 93

Getting a List of Attributes 95

Adding an Element 96

Changing an Element’s Enclosed Text 97

Deleting an Element 98

Adding an Attribute 98

Changing an Attribute 99

Deleting an Attribute 99

Escaping Characters for XML 100

Transforming Using XSLT 100

Validating Your XML 102

A Simple RSS Parser 103

10 Rapid Applications Development with GUI

Toolkits 107

A Simple GTK+ Hello World 108

Using Glade 110

A Simple Qt Hello World 115

Attaching a Signal Handler to a Qt

Widget Slot 116

Using Qt Designer 118

Attaching Signal Handlers to Qt Designer

Generated Code 124

11 Simple CGI Forms 127

Processing a Web Form 128

Returning Tabled Results 131

Escaping Input 134

Locking Down Ruby 136

Receiving an Uploaded File 137

Representing Data Graphically 138

12 Connecting to Databases 143

Opening (and Closing) a MySQL Database

Connection 144

Creating a Table 145

Getting a List of Tables 146

Adding Rows to a Table 146

Iterating Over Queried Rows 147

Deleting Rows 147

Deleting a Table 148

13 Working with Networking and Sockets 151

Connecting to a TCP Socket 152

Running a TCP Server on a Socket 153

Serializing Objects with YAML 156

Network Objects with Distributed Ruby 158

Using Net::HTTP 159

Using Webrick 160

14 Working with Threads 163

Creating a Thread 164

Using a Timer 165

Killing a Thread 168

Synchronizing Thread Communication 169

Multithreaded Exception Gathering 172

15 Documenting Your Ruby 175

Documenting Ruby Code 176

Typographic Conventions Used 177

Overriding Method Signatures in

Documentation 179

Hiding a Module, Class, or Method 180

Providing Program Usage Help 180

Generating HTML Documentation 182

Generating and Installing Documentation for ri 183

16 Working with Ruby Packages 185

Installing a Module 187

Removing a Module 188

Searching for a Module 188

Updating Modules 188

Examining a Module 189

Packaging Your Module with Hoe 189

Creating a Simple Test Case 190

Distributing Your Module on RubyForge 191

Making Rakefile Standalone 192

Index 195

Read More Show Less

Preface

Introduction

Audience

You can find some great Ruby books on the market. If you are new to Ruby, a friend or someone on the Internet has probably already listed some favorite Ruby books—and you should buy those books. But every book has its niche: Each attempts to appeal to a certain need of a programmer.

It is my belief that the best thing this book can do for you is show you the code. I promise to keep the chat to a minimum, to focus instead on the quality and quantity of actual Ruby code. I'll also keep as much useful information in as tight a space as is possible.

Unlike any other book on the market at the time of this writing, this book is intended to be a (laptop-bag) "pocket-size" resource that enables you to quickly look up a topic and find examples of practical Ruby code—a topical quick reference, if you will. In each of the topics covered, I try to provide as thorough an approach to each task as the size allows for; there's not as much room for coverage of topical solutions as there is in much larger books with similar goals, such as The Ruby Way, 2nd Edition (Sams, 2006), by Hal Fulton. Because of this, other issues that are often given equal priority are relegated to second. For instance, this is not a tutorial; the code samples have some explanation, but I assume that you have a passing familiarity with the language. Also, when possible, I try to point out issues related to security and performance, but I make no claim that these are my highest priority.

I hope that you find this book a useful tool that you keep next to your keyboard whenever you are phrase-mongering in Ruby.

How to Use This Book

I have not intended for this book to be read cover to cover. Instead, you should place your bookmark at the Table of Contents so you can open the book, find the topic you are programming on at the moment, and go immediately to a description of all the issues you might run into.

The content in the book is arranged by topic instead of Ruby class. The benefit is that you can go to one place in this book instead of four or five areas in Ruby's own documentation. (Not that there's anything wrong with Ruby's documentation. It's just that sometimes you are working with several classes at a time and, because Ruby's docs are arranged by class, you have to jump around a lot.)

Conventions

Phrases throughout the book are put in dark gray boxes at the beginning of every topic.

Phrases look like this.

Code snippets that appear in normal text are in italics. All other code blocks, samples, and output appear as follows:

# code sample boxes.

Parentheses are optional in Ruby in some cases—the rule is: you must have parentheses in your method call if you are calling another function in your list of parameters, or passing a literal code block to the method. In all other cases, parentheses are optional. Personally, I'm a sucker for consistency but one of the indisputable strengths of Ruby is the flexibility of the syntax.

In an attempt to have consistency between this book and others, I will (reluctantly) use .class_method() to refer to class methods, ::class_variable to refer to class variables, #method() to refer to instance methods, and finally #var to refer to instance variables. When referring to variables and methods which are members of the same class, I'll use the appropriate @variable and @@class_varriable.

I know that some people might find these two rules annoying—especially those coming from languages that use the '::' and '.' notation everywhere. In all practicality, you will never be so consistent—and rightfully so. One of Ruby's strengths is that there is a ton of flexibility. In fact, this flexibility has helped make Ruby on Rails so popular. This allowed the creators of Rails to make what appears to be a domain-specific language (a language well-suited for a specific kind of work) for web development. But really, all that is going on is a variation on Ruby syntax. And this is one of the many reasons that Ruby is more suitable for a given problem than, say, Python. Python's rigidity ("there should be one—and preferably only one—obvious way to do it") doesn't lend itself to DSL, so the programmers in that language are forced to use other means (which might or might not turn out to be unpleasant).

I always use single quotes (') in Ruby code unless I actually want to make use of the double-quote (")features (interpolation and substitution).

I always put the result of the evaluation of the statement (or block) on the next line with a proceeding #=>, similar to what you would find if you were using irb or browsing Ruby's documentation.

Comments on executable lines of code start with # and are in italics to the end of the comment. Comments on #=> lines are in parentheses and are in italics.

Acknowledgments

Without the Pragmatic Programmers' freely available 1st Edition of Programming Ruby, I would have never discovered the wonderful world of Ruby. The Pickaxe books and the great Ruby community are what make projects like this one possible.

Thanks to my loving partner, Brandon S. Ward, for his infinite patience while working on this book.

Reporting Errata

Readers will almost certainly find topics that they wish were covered which we were overlooked when planning this book. I encourage you to please contact us and let us know what you would like to see included in later editions. Criticisms are also welcome. Contact information can be found in the front-matter of this book.

© Copyright Pearson Education. All rights reserved.

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)