title: Ruby custom method to fill hash
body: <p>I'm working on a method that will allow me to add in a "word" and its "definition", into a hash.</p>
  
  <p>Here's what I have:</p>
  
  <pre><code>class Dictionary
  def entries
   @entries ||= {}
  
  end
  
  def add word, definition = nil
      entries[word] = definition
      "#{entries}"
  end
  
  end
  </code></pre>
  
  <p><strong>Note:</strong> I want the definition parameter to be optional, hence my initialization to nil.  However, for some reason that is showing up in my output.</p>
  
  <p>Example: Passing in "fish" and "aquatic animal":</p>
  
  <p><strong>My output:</strong> <code>{{"fish"=&gt;"aquatic animal"}=&gt;nil}</code></p>
  
  <p><strong>Desired output:</strong> <code>{"fish"=&gt;"aquatic animal"}</code></p>
  
  <p>It seems like the problem is that it's putting both values that I pass to the method into the first key in the hash, and is putting that "nil" value into that key's value.  Where am I making an error?</p>
  
  <p><strong>Edit:</strong> Adding the relevant RSpec block that is doing the method call so that I can better understand exactly how RSpec is making this call:</p>
  
  <pre><code>describe Dictionary do
    before do
      @d = Dictionary.new
    end
  
    it 'is empty when created' do
      @d.entries.should == {}
    end
  
    it 'can add whole entries with keyword and definition' do
      @d.add('fish' =&gt; 'aquatic animal')
      @d.entries.should == {'fish' =&gt; 'aquatic animal'}
      @d.keywords.should == ['fish']
    end
  </code></pre>
  
  <p>Thanks!</p>