Archive for the ‘ruby’ Category

16 April

RubyGems: RDoc Information on Installed Gems

It can be useful to view the RDoc information for the various gems you may have installed on your local system. RubyGems provides a way to do this by starting up a local RDoc server.

Local Gem Server
To start the server, open a command window on the machine that has RubyGems installed and type:

gem server

Once the you get a message that the server is starting, you can minimize this command window (don’t close it or the server will stop).

Using your browser of choice, navigate to http://localhost:8808.

When you open this page, you will see a list of all the gems you have installed on the local system and each one will have an WWW link that will open the project’s homepage as well as an RDoc link that will open the RDoc information for that particular gem. At the top of the page are three columns: Files, Classes and Methods. I tend to find Classes and Methods the most useful when trying to discover usage and syntax for a gem.

If you click on methods displayed in the RDocs, an small pop-up will open to show you the code relating to the method. This can be even more useful if you are trying to figure out how to use a method.

Missing RDoc Information
There might be a situation where you have a gem installed that does not have RDoc information but you can force RubyGems to generate RDoc information for already installed gems.

gem rdoc --all

This will generate the RDoc information for all installed gems. You can also generate RDoc for select gems only by using:

gem rdoc GEMNAME

11 March

Ruby Gems – Basic Management

Ruby Gems can be a little interesting to manage, especially to someone as new to it as I am. In the course of my own self-education, I’ve compiled a little list of what I consider the basic commands. Hopefully this will be of some help to others as well.

Gem Sources

To see which gem servers or repositories your installation of RubyGems is using, open a command prompt and type:

gem sources

The system will return with a list of the repositories and caches Ruby is using to look for gems. In the case of my local system, I got back:

C:\>gem sources

Which shows that my system is only looking at RubyForge for its gems right now. This can be useful to know if you get errors that gems cannot be found.

Installing Gems

To install a new gem, you can open a command prompt and type:

gem install gemname

This will install the latest version of the gem gemname from the repository(ies) your local system knows about.

If you have a local copy of the gem and you need to install that particular one, you can open a command prompt, navigate to the directory that contains the local copy and type:

gem install gemname --local

If you need only a particular version of a gem that might not be the latest version you’d get by default, you can open a command prompt and type:

gem install gemname --version #.#.#

This will install version #.#.# of gem gemname.

Uninstalling Gems

Uninstalling a gem can be done by opening a command prompt and typing:

gem uninstall gemname

This will uninstall the gem gemname. If you have more than one version of that gem installed, RubyGems will display a numbered list of the versions and you can enter the number of the version you want to uninstall or choose to uninstall all versions of gem gemname.

Updating Gems

You can update installed gems by opening a command prompt and typing:

gem update gemname

This will update the gem gemname to the latest version in the gem repository RubyGems is pointing to.

Updating the RubyGems System

Sometimes you will need to update the actual RubyGems management system. To do this, open a command prompt and type:

gem update --system

If you are having problems updating your gems or using them, it usually won’t hurt to try to do this update.

Check Gem Dependencies

If you need to know what the dependencies of an installed gem are, you can open a command prompt and type:

gem dependency gemname

This will list the dependencies of the gem gemname.

Gem Help

There is a good amount of help embedded in the RubyGems system. Often you can answer your own questions on how to manipulate your gems using this help. To access the list of commands, open a command prompt and type:

gem help commands

To get help on an individual command, open a command prompt and type:

gem help command

6 March

Come on in, the Watir’s fine!

This has been an interesting week for me. I am immersing myself in Watir (Web Applications Testing in Ruby), an open-source library for automating web browsers that works with Ruby, an open-source, object-oriented programming language I’m starting to really like it!

This is a great boon to those of us who have to write automation quickly that need to also be maintainable and not cost an arm and a leg to buy tools for. While some tools do exist, they tend to be expensive or brittle – or both.

The one thing I really am discovering is that there is a mixed bag of documentation and a lot of room for better documentation and training materials. Maybe it’s a place I can turn my writing skills.