In this section we are going to add our very own iterators to the class AddressBook. We will create two iterators, AddressBook#each and AddressBook#each_address, which can be used as usual:





Hashes are a generalization of arrays. Instead of only permitting integer indices, as in array[3], hashes allow any object to be used as an "index". So, you can write hash["name"]





We chose to represent the addressbook as an array because arrays have an associated order. Say that we want to change that order. Suppose, for instance, that we want to sort the array alphabecially. How do we do that?





Hereafter, we discuss the difference between using Gtk+ from C and using Ruby/Gtk





Now we will learn how to do things with the address book. Especifically, we will learn how to print and how to sort the addressbook.





I went milling about for source for progress bars that would be suitably embedded within a Ruby on Rails application I'm working on and came up with nada. Sure, sure there are lots of bars that have to do with live uploading and whatnot but nothing that grabbed me with the interface I was looking for (call function, return data).





An iterator is a special kind of method. It is a method that lets you access items one at a time.





There are just a couple more things that we should do with our AddressBook class.





There are lots of reasons to like Ruby. It's a pure object oriented language. The syntax is elegant, and the use of blocks creates a novel feel. Another reason to like Ruby is its scalability. I don't mean scalability in the performance sense, but in regards to how you can code simple Ruby macros to solve small problems and also use Ruby in its object oriented form to support very large or complex...





This is all very nice, but can I do anything cool with arrays? You sure can. Follow this tutorial and ou will find out how.





An addressbook is a fairly complex structure. It contains several contacts, and each one has an associated name, address and so on.





Now we are ready to create our very own Address class. Let's start simple. Let's start with an address that only contains the "street" field.





You are already familiar with a couple of Ruby classes (Integer and String). The class Array is used to represent a collection of items.





he first step is very simple. AddressBook has an array which contains all our contacts. We will not use attr_accessor because we don't want the user to access this array directly. We will write our own access methods.












