Nuby question re a method

From: vanjac12@yahoo.com [mailto:vanjac12@yahoo.com]

Question 1.
Is this the same as the following?

class AddressBook
def each
@persons.each
do |p|
yield p
end
end
end

There’s some precedence difference between do…end and {}, but semantically
they’re the same.

defining the method each on the Class AddressBook (an array of hashes;
the addressbook is an array of persons, each person is a hash;
his name, address, etc.)
Question 2. Is my terminology correct? If not, is the meaning
clear enough?

Terminology and meaning are pretty much right, but I’d say there’s a
reasonable difference in Ruby between “defining the method each ON the
Class” (emphasis mine) and defining the method each in the Class, on the
instance. But that’s being picky: you knew what you meant, and so did I.

(In case that was unclear, you could define the method “on the class
addressbook” with def AddressBook.each(); …; end). If thats still unclear,
ignore the whole last 2 paragraphs.

David.

···

-----Original Message-----

David Naseby david.naseby@eonesolutions.com.au wrote in message news:C1B5ED61365AD511805500D0B7B697C633DB68@SYDEONE
Thanks for both responses. In particular for the syntax error.
irb probably would have told me something, but I learned in
Fortran 25-35 years ago, and its hard to change old habits.

(I keep wanting to use GO TO statements, even though I learned
that it was not a good idea a long time ago.
And I will never forget my extensive use of Fortran do loops.)

Van