How to access a class variable from the outside in ruby?
<p>I'm trying to access a class variable from a method outside of the class.</p>

<p>This is my class:</p>

<pre><code>class Book

  @@bookCount = 0
  @@allBooks = []

  def self.allBooks
    @@allBooks
  end

  def self.bookCount
    @@bookCount
  end

  attr_accessor :name,:author,:date,:genre,:rating

  def initialize(name, author, date, genre, rating)
      @name = name
      @author = author
      @date = date
      @genre = genre
      @rating = rating
      @@bookCount += 1
      @@allBooks &lt;&lt; self
  end

end
</code></pre>

<p>This is the method trying to access the class variable @@bookCount</p>

<pre><code>def seeBookShelf
  if @@bookCount == 0
    puts "Your bookshelf is empty."
  else
    puts "You have " + @bookCount + " books in your bookshelf:"
    puts allBooks
  end
end
</code></pre>

<p>When I try to execute the method I get this:</p>

<pre><code>undefined local variable or method `bookCount' for main:Object (NameError)
</code></pre>

<p>How can I access bookCount from the outside?</p>