From: Pit Capitain Date: 2008-08-20T04:32:19+09:00 Subject: Re: Find element in array of hashes I'm not Robert, but at least we both live in the same country, so I'll answer anyway: 2008/8/19 Adgar Marks : > Dear Robert, > > I read your answer and also tried it! If you really tried it, then you haven't looked at the result of the method #find. Just try each step in IRB and look at the results. > If it would have been a simple Array, then i wouldnt have need to ask it > in the forum, because it is trivial. > > Example from http://www.ruby-doc.org/core/ > a = [ "a", "b", "c" ] > a.include?("b") #=> true > a.include?("z") #=> false You do have simple arrays, too, but the elements are not strings but hashes, so you can't compare them as easily as strings. If you would define classes for your objects with appropriate comparison methods, then your code could look as simple as the one you've shown. > I read your remark: > "But note that this is inefficient if you have multiple entries in both > arrays." > whic is exaclty my case, which i tried to explain my writing: > ... > i thought i explained my problem clearly, that my arrays are > multidimentions, by writing that they dont have the same size and > explain the structre of each Array of hashes. I'm sure Robert understands your problem exactly, but it seems you don't understand his answer, in which he mentioned a more efficient data structure: hashes of hashes. > I am not a Ruby expert and neither an expert programer, that is why i am > asking for help. From what I can tell of Robert's posts he is both a Ruby (at least an #inject :-) expert and an expert programmer, and he already gave you the answer to your question (again: just try it) plus a hint how you should change your data structures. Regards, Pit