On Sun, Oct 30, 2011 at 12:18, Faith T. [email protected] wrote:
There are two objects
with two arrays that need to comply with the algorithm, not just one,
this is the biggest problem for me… I haven’t worked with two arrays
yet. Can you suggest any coding?
Mainly: don’t tie your code to either of the objects or their classes.
Instead, write a function that can accept a string from any source,
so that either object can use it, and so can anything else that might
want to. That’s what we call “loose coupling”, and it’s a Good Thing.
Then you won’t care that the string you’re trying to find the right
article for, is the result of pulling things out of two arrays. (I’m
assuming this is from the “array of adjectives and array of nouns”
title-making exercise you posted about earlier.)
As for specific code samples, no, that’s exactly what I’m trying to
avoid. It might be easier in the short term, for you, and in fact for
the rest of us, if we just gave you some code. But I want you to
understand the concept behind the code, and then come up with the
translation of concept into code, yourself.
But I suppose I could give you a skeleton to illustrate a few things.
In Ruby, code doesn’t have to be inside a class. You can just define
a function like so:
def article str
# insert logic here
end
completely outside of any class. By contrast, in some other
languages, such as Java, all code has to be in a class, such as:
class ArticleMaker
# possibly put an initializer method here
# maybe some more methods
def makeArticle
# insert logic here
end
# maybe yet more methods
end
See how much more useless overhead there is in the second example? We
love that Ruby doesn’t make us do that. 
Anyway, now you just have to figure out first what logic should be in
that first example, and second how to express it in Ruby.
-Dave