title: Initializing attributes in Ruby objects
body: <p>I create a new object of type Spam, with attr_accessor to both hooray and name and I have the initialize method. I'm expecting when I create a new object the object is loaded with a var of name with "Whammy" and a empty array named hooray. Though I'm not getting this behavior. Can anyone explain, thank you in advance.</p>
  
  <pre><code>module Test
  class Spam
   attr_accessor :hooray, :name
  
   def initialize
      hooray = []
      name = "Whammy"
   end
  end 
  end
  
  Loading development environment (Rails 3.0.0)
  irb(main):001:0&gt; require 'Test'
  =&gt; nil
  irb(main):002:0&gt; test = Test::Spam.new
  =&gt; #&lt;Test::Spam:0x000000031ff470&gt;
  irb(main):003:0&gt; test.name
  =&gt; nil
  irb(main):004:0&gt; test.hooray
  =&gt; nil
  irb(main):005:0&gt; test.hooray &lt;&lt; 5
  NoMethodError: You have a nil object when you didn't expect it!
  You might have expected an instance of Array.
  The error occurred while evaluating nil.&lt;&lt;
      from (irb):5
      from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands/console.rb:44:in `start'
      from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands/console.rb:8:in `start'
      from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands.rb:23:in `&lt;top (required)&gt;'
      from script/rails:6:in `require'
      from script/rails:6:in `&lt;main&gt;'
  irb(main):006:0&gt; 
  </code></pre>