title: Ruby variable scope
body: <p>I've been looking at learning a new dynamic scripting language for web development and after agonising over Python and Ruby, as I really liked both, I've decided to pick Ruby (It pretty much came down to a coin toss and the fact there are more RoR jobs in the UK than Python/Django). My question is about scope in Ruby. Do I have to declare a class attribute inside a method to be able to access it from other methods?</p>
  
  <p>For example, I cannot do</p>
  
  <pre><code>class Notes
    @notes = ["Pick up some milk"]
  
    def print_notes
      puts @notes
    end
  end
  </code></pre>
  
  <p>It seems I have to declare attributes I want to use in the constructor? This example works:</p>
  
  <pre><code>class Notes
    def initialize
      @notes = ["Pick up some milk"]
    end
  
    def print_notes
      puts @notes
    end
  end
  </code></pre>
  
  <p>Is this right? I've noticed prefixing example one with @@ instead of @ works but to my understanding if the class has a subclass (say, Memo) then any changes to attributes prefixed with @@ in Notes would change the value in Memo?</p>
  
  <p>Sorry if this is a repeat question, just a lost noobie :)</p>