Hello, everyone! What would be the quickest/best way to check elements
of an array, which themselves are arrays of hashes? Quick example:
mov1 = {"title"=>"Batman Returns", "genre"=>"Action"}
mov2 = {"title"=>"Batman", "genre"=>"Action"}
mov3 = {"title"=>"Batman Begins", "genre"=>"Action"}
mov4 = {"title"=>"The Dark Knight", "genre"=>"Action"}
array = mov1, mov2, mov3, mov4
Right now, to search for "Batman Beings", for instance, I'm using:
puts array.each { |i|
if i["title"] == "Batman Begins"
puts "Found!"
break # ends the searching because item is found
end
}
Is there a better or faster way to do this in Ruby? I'm going to be
looking through much more data then this, so I want the most efficient
code possible. I'm just a beginner, so this is pretty much all I know
how to do in Ruby.
--
Posted via http://www.ruby-forum.com/.