[Courses] [Ruby] Lesson 2: Iterators
jennyw
jennyw at dangerousideas.com
Fri Dec 9 18:30:06 EST 2005
Anne G wrote:
>What I wanted was three independent objects which did their
>bit and told each other when to get started, but in the
>actual implementation, it does not work I think because the
>three objects are not actually independent. Each time we
>call on an object, we tie a know which we have to untie at
>some point.
>
>
Hi, Anne,
I went back and read through your e-mails ... I wasn't sure what you're
trying to accomplish with the three objects. Is this an abstract example
or is there a practical application? It looked very abstract to me, so
it was hard to figure out what you're trying to accomplish.
Going back, I see you were asking how to send messages to objects. You
just do it like this ... object.message. For example,
fruits = ['apple', 'pear', 'banana'] # an array of fruits
fruits.first # send the message #first to the fruits object. it
returns a string: 'apple'
fruits.first.class # you can also send two messages in a row -- for
example, this sends #class to 'apple'. It'll return the class, String.
You also asked how can you can have two objects that do things and ask
each other to do something. I see that you have the objects calling each
other, and some recursive methods, but this is all implementation --
what I'm not clear on is the problem that this is the proposed solution
for. I don't think this is so much a Ruby thing as it is a design
issue. It could well be that there's a design pattern that matches
exactly what you want to do -- if we figure out what that is, it should
be a lot easier to show it in Ruby. I guess the first step might be to
come up with a practical example (i.e. a user story). You might have
done this, of course, and I may have missed it, so apologies if that's so.
Good luck!
Jen
More information about the Courses
mailing list