title: Ruby array methods for locating based on an object's attribute?
body: <p>Say I have a Ruby class, <code>Flight</code>. <code>Flight</code> has an <code>attr_accessor :key</code> on it. If there's an array of instances of this class: <code>flights = [flight1, flight2, flight3]</code>, I have a "target key", say "2jf345", and I want to find a flight based on it's key, from that array - what sort of code should I use?</p>
  
  <p>This is the code I was going to use: </p>
  
  <p><code>flights[flights.map { |s| s.key }.index(target_key)]</code></p>
  
  <p>But it seems like with Ruby, there should be a simpler way. Also, the code above returns an error for me - <code>`[]': no implicit conversion from nil to integer (TypeError)</code>. I assume this means that it's not returning an index at all.</p>
  
  <p>Thanks for any help.</p>