Brian Schröäer wrote:

> Anyhow, here is how to define a class variable and class methods.
>
> class Klass
>   @@foo = []
>
>   def self.add(bar)
>     @@foo << bar
>   end
>
>   def self.foo
>     @@foo
>   end
> end
>
> Klass.add(1)
> Klass.add(2)
> p Klass.foo

OK, am struggling with translating this to my example.  Here's what
I've done:

    articles.read.scan(article_page).each do |url|
      article_url = "#{base_url}#{url}"
      open(article_url) do |article|
        article_text = article.read
        title = article_text.scan(title_match).to_s
        author = article_text.scan(author_match).to_s
        puts "loading #{title} ...\n"
        a = Article.new(title, author, article_url)
        a.add
      end

.... and then:

File.open("articles.yaml", "w") {|f| YAML.dump(p Article.articles, f)}

But I get a "undefined method `add'" error. I have that part of the
class defined like so:

class Article
  include Journals

  @@articles = []

  attr_reader :title, :author, :url

  def initialize(title, author, url)
    @title = title
    @author = author
    @url = url
  end

  def self.add(article)
    @@articles << article
  end

  def self.articles
    @@article
  end

  ...

> good luck with ruby,

Thanks!

Bruce