title: private method `select' called for nil:NilClass (NoMethodError)
body: <p>I am new to ruby and would love some help please :)</p>
  
  <p>I fixed the error in my ruby code, but I'm confused as to WHY the fix works.</p>
  
  <p>I get the following error <strong>private method `select' called for nil:NilClass (NoMethodError)</strong> when I type in the following line:</p>
  
  <pre><code>scanned = @keywords.select { |key| key.match(word) }
  </code></pre>
  
  <p>, which is located within the following method:</p>
  
  <pre><code>def find(word)
      return {} unless @entries.any?
      scanned = @keywords.select { |key| key.match(word) }
      found ={}
      if scanned.any? 
          scanned.each do |x| found.merge!( { x =&gt; @entries[x] } )
          end
      else
          {}
      end
      found
  end
  </code></pre>
  
  <p>,yet this error goes away if I replace the erroneous line above with the following:</p>
  
  <pre><code>scanned = @entries.keys.sort.select { |key| key.match(word) }
  </code></pre>
  
  <p>I define @keywords as @keywords = @entries.keys.sort in the class structure below... <strong>Why can't I use '.select' on @keywords yet I can use it on @keywords' contents?</strong></p>
  
  <pre><code>class Dictionary
  def initialize
      @entries = {}
  end
  
  def entries
      @entries
  end
  
  def add(entry)
      @entries = entry.is_a?(Hash) ? @entries.merge!(entry) : @entries.merge!( {entry =&gt; nil} )
  end
  
  def keywords
      @keywords = @entries.keys.sort
  end
  
  def include?(keyword)
      @entries.keys.include?(keyword)
  end
  
  def find(word)
      return {} unless @entries.any?
      scanned = @keywords.select { |key| key.match(word) }
      found ={}
      if scanned.any? 
          scanned.each do |x| found.merge!( { x =&gt; @entries[x] } )
          end
      else
          {}
      end
      found
  end
  
  def printable
      printable = @entries.sort.map do |key, value| %Q{[#{key}] "#{value}"}
      end
      printable.join("\n")
  end
  end
  </code></pre>