or
Sign in to turn on 1-Click ordering.
or
Amazon Prime free trial required. Sign up when you check out. Learn more
More Buying Choices
Have one to sell? Sell yours here
or
Get a £0.25 Amazon.co.uk Gift Card
Programming Ruby: The Pragmatic Programmer's Guide, Second Edition
 
See larger image
 
Tell the Publisher!
I’d like to read this book on Kindle

Don't have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.

Programming Ruby: The Pragmatic Programmer's Guide, Second Edition [Paperback]

Dave Thomas , Chad Fowler , Andy Hunt
4.6 out of 5 stars  See all reviews (7 customer reviews)
RRP: £34.50
Price: £24.38 & this item Delivered FREE in the UK with Super Saver Delivery. See details and conditions
You Save: £10.12 (29%)
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
In stock.
Dispatched from and sold by Amazon.co.uk. Gift-wrap available.
Only 1 left in stock--order soon (more on the way).
Want guaranteed delivery by Thursday, May 31? Choose Express delivery at checkout. See Details
‹  Return to Product Overview

Product Description

Product Description

Ruby is an increasingly popular, fully object-oriented dynamic programming language, hailed by many practitioners as the finest and most useful language available today. When Ruby first burst onto the scene in the Western world, the Pragmatic Programmers were there with the definitive reference manual, Programming Ruby: The Pragmatic Programmer's Guide.

Now in its second edition, author Dave Thomas has expanded the famous Pickaxe book with over 200 pages of new content, covering all the improved language features of Ruby 1.8 and standard library modules. The Pickaxe contains four major sections:

  • An acclaimed tutorial on using Ruby.
  • The definitive reference to the language.
  • Complete documentation on all built-in classes, modules, and methods
  • Complete descriptions of all 98 standard libraries.


If you enjoyed the First Edition, you'll appreciate the expanded content, including enhanced coverage of installation, packaging, documenting Ruby source code, threading and synchronization, and enhancing Ruby's capabilities using C-language extensions. Programming for the World Wide Web is easy in Ruby, with new chapters on XML/RPC, SOAP, distributed Ruby, templating systems, and other web services. There's even a new chapter on unit testing.

This is the definitive reference manual for Ruby, including a description of all the standard library modules, a complete reference to all built-in classes and modules (including more than 250 significant changes since the First Edition). Coverage of other features has grown tremendously, including details on how to harness the sophisticated capabilities of irb, so you can dynamically examine and experiment with your running code. "Ruby is a wonderfully powerful and useful language, and whenever I'm working with it this book is at my side" --Martin Fowler, Chief Scientist, ThoughtWorks

From the Publisher

The famous Pickaxe book (so named for the tool on the cover) is the definitive reference to the highly-regarded Ruby programming language. Author Dave Thomas has expanded the new Second Edition with over 200 pages of new material and major enhancements from the original, covering all the new and improved language features of Ruby 1.8 and standard library modules.

About the Author

Dave Thomas and Andy Hunt have more than 50 years combined experience, developing software for clients around the world. For the last 10 years they've been working together as The Pragmatic Programmers, helping clients write software and improve their development processes. They are authors of the best-selling The Pragmatic Programmer, and have written several other books. They speak at conferences globally, and are editors of IEEE Software's "Construction" column. Chad Fowler is co-director of Ruby Central, Inc., and remains an active, driving force in the Ruby community.

Excerpted from Programming Ruby: The Pragmatic Programmer's Guide by Dave Thomas, Chad Fowler, Andy Hunt. Copyright © 2004. Reprinted by permission. All rights reserved.

Chapter 17 Package Management with RubyGems

Chad Fowler is a leading figure in the Ruby community. He’s on the board of Ruby Central, Inc. He’s one of the organizers of RubyConf. And he’s one of the writers of RubyGems. All this makes him uniquely qualified to write this chapter.

RubyGems is a standardized packaging and installation framework for libraries and applications, making it easy to locate, install, upgrade, and uninstall Ruby packages. It provides users and developers with four main facilities.

1. A standardized package format,
2. A central repository for hosting packages in this format,
3. Installation and management of multiple, simultaneously installed versions of the same library,
4. End-user tools for querying, installing, uninstalling, and otherwise manipulating these packages.

Before RubyGems came along, installing a new library involved searching the Web, downloading a package, and attempting to install it—only to find that its dependencies haven’t been met. If the library you want is packaged using RubyGems, however, you can now simply ask RubyGems to install it (and all its dependencies). Everything is done for you.

In the RubyGems world, developers bundle their applications and libraries into single files called gems. These files conform to a standardized format, and the RubyGems system provides a command-line tool, appropriately named gem, formanipulating these gem files.

In this chapter, we’ll see how to

1. Install RubyGems on your computer.
2. Use RubyGems to install other applications and libraries.
3. Write your own gems.After downloading
and unpacking the distribution, you can install it using the included installation script.

% cd rubygems0.7.0
% ruby install.rb

Depending on your operating system, you may need suitable privileges to write files into Ruby’s site_ruby/ and bin/ directories.

The best way to test that RubyGems was installed successfully also happens to be the most important command you’ll learn.

% gem help
RubyGems is a sophisticated package manager for Ruby. This is a basic help message containing pointers to more information.

Usage:
gem h/
help
gem v/
version
gem command [arguments...] [options...]
Examples:
gem install rake
gem list local
gem build package.gemspec
gem help install
Further help:
gem help commands list all 'gem' commands
gem help examples show some examples of usage
gem help show help on COMMAND
(e.g.

Because RubyGems’ help is quite comprehensive, we won’t go into detail about each of the available RubyGems commands and options in this chapter.

Installing Application Gems

Let’s start by using RubyGems to install an application that is written in Ruby.Not only that, but it’s generally a great tool to have around, as it is a build tool similar to Make and Ant. In fact, you can even use Rake to build gems!

Locating and installing Rake with RubyGems is simple.

% gem install r
rake
Attempting remote installation of 'Rake'
Successfully installed rake, version 0.4.3
% rake version
rake, version 0.4.3

RubyGems downloads the Rake package and installs it. Because Rake is an application, RubyGems downloads both the Rake libraries and the command-line program rake.

You control the gem program using subcommands, each of which has its own options and help screen. In this example, we used the install subcommand with the -r option, which tells it to operate remotely. (Many RubyGems operations can be performed either locally or remotely. For example, you can to use the query command either to display all the gems that are available remotely for installation or to display a list of gems you
already have installed. For this reason, subcommands accept the options –r and-l, specifying whether an operation is meant to be carried out remotely or locally.)

If for some reason—perhaps because of a potential compatibility issue—you wanted an older version of Rake, you could use RubyGems’ version requirement operators to specify criteria by which a version would be selected.

% gem install r
rake v
"< 0.4.3"
Attempting remote installation of 'rake'
Successfully installed rake, version 0.4.2
% rake version
rake, version 0.4.2

Table 17.1 on the following page lists the version requirement operators. The -v argument in our previous example asks for the highest version lower than 0.4.3.

There’s a subtlety when it comes to installing different versions of the same application with RubyGems. Even though RubyGems keeps separate versions of the application’s library files, it does not version the actual command you use to run the application. As a result, each install of an application effectively overwrites the previous one.

During installation, you can also add the -t option to the RubyGems install command, causing RubyGems to run the gem’s test suite (if one has been created). If the tests fail, the installer will prompt you to either keep or discard the gem. This is a good way to gain a little more confidence that the gem you’ve just downloaded works on your system the way the author intended.

% gem install SomePoorlyTestedProgram t
Attempting local installation of 'SomePoorlyTestedProgram1.0.1'
Successfully installed SomePoorlyTestedProgram, version 1.0.1
23 tests, 22 assertions, 0 failures, 1 errors...keep Gem? [Y/n] n
Successfully uninstalled SomePoorlyTestedProgram version 1.0.1

Had we chosen the default and kept the gem installed, we could have inspected the gem to try to determine the cause of the failing test.

Both the require_gem method and the add_dependency attribute in a Gem::Specification accept an argument that specifies a version dependency. RubyGems version dependencies are of the form operator major.minor.patch_level. Listed below is a table of all the possible version operators.

‹  Return to Product Overview

Amazon.co.uk Privacy Statement Amazon.co.uk Delivery Information Amazon.co.uk Returns & Exchanges