From: Bruce D'Arcus Date: 2005-06-07T05:40:26+09:00 Subject: Re: newbie read.scan (?) question Ghislain Mary wrote: > Because your author and title probably aren't strings as you expect them > to be but rather arrays. Ah, right. Using scan returns an array. On this ... > > I have these two classes: > > > > class Article > > > > include Journals > > > > attr_reader :title, :author, :description, :url > > def initialize(title, author, url) > > @title = title > > @author = author > > @url = url > > end > > > > def to_s > > "#@title, #@author" > > end > > > > def abstract > > # > > end > > > > def refer > > Journals::const_get(:BASE_URL) + "/" + > > @url + "&form=refer&file=file.txt" > > end > > > > def pdf > > Journals::const_get(:BASE_URL) + "/" + > > @url + "&form=pdf&file=file.pdf" > > end > > end > > > > class Articles > > # > > attr_reader :articles > > > > def initialize > > @articles = Array.new > > end > > > > def append(article) > > @articles.push(article) > > self > > end > > > > def [](index) > > @articles[index] > > end > > end > > Why create an Article class and an Articles class? Because I'm *real* newbie! My only programming background is with XSLT. So I'm trying to also understand basic OO design in this example. > You could make all > the content of your Articles class also content of the Article class but > at the class level instead of the instance level. So you just have to > transform your @articles variable into @@articles and define your append > and [] methods as self.append and self.[]. Can you give me an abbreviated example of how to do actually do this? For example, how do I define @@articles under the Article class, and how would I then define the append method there. > An other thing: I don't think you need to use > Journals::const_get(:BASE_URL). You could simply use Journals::BASE_URL. Ah thanks. It took me awhile just to get that far! Bruce