Choose one of the following two links to downlod a .tar.gz or .zip file containing example code from the book The Ruby Programming Language, by David Flanagan and Yukihiro Matsumoto and published by O'Reilly Media. (ISBN 978-0-596-51617-8):
RPLExamples.tar.gz
RPLExamples.zip
The files with ".rb" extensions are numbered examples from the book. Example 1-1, for example is in the file 1-1.rb. That first example is a complete working Ruby program for solving Sudoku puzzles. Most of the other numbered examples, however, consist of class and method definitions and cannot be run as standalone programs.
Most of the code in the book takes the form of unnumbered examples. The files with ".txt" extensions consist of code extracted from each of the chapters of the book. For example, the file Chapter1Listings.txt contains all of the code from Chapter 1, including example 1-1. If, while reading Chapter 1, you find some code that you'd like to try out, you can cut-and-paste it from this file.
This code, like the book it is taken from, is copyright (c) 2008 by David Flanagan and Yukihiro Matsumoto, but you can use it under the terms described in the book's preface:
Using Code Examples
This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product's documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "From _The Ruby Programming Language_ by David Flanagan and Yukihiro Matsumoto. Copyright 2008 David Flanagan and Yukihiro Matsumoto, Published by O'Reilly Media. ISBN 978-0-596-51617-8."
If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com.
If you find this code helpful, we'd appreciate it if you'd buy a copy of the book.