From: Harry Kakueki Date: 2009-09-18T15:10:26+09:00 Subject: Re: simple question: compare words On Fri, Sep 18, 2009 at 2:14 PM, Ahmet Kilic wrote: > I want to compare same words in a and b then, > I wrote this, > > $ye > $bu > a = "ali", "bel", "del","en" > b = "ali","bas","del","sx","en","sz","zen" > > for xa in a > $ye= xa > end > b.each do |bx| > $bu = bx > if $ye == $bu > puts "#{$ye} and #{$bu}" > end > end > > result: > => en and en > > but result is only "en and en". why the last one? > where is the others ali and del??? > -- Maybe this will do what you want. a = ["ali", "bel", "del","en"] b = ["ali","bas","del","sx","en","sz","zen"] p a&b But, to kind of answer your question, a = ["ali", "bel", "del","en"] b = ["ali","bas","del","sx","en","sz","zen"] for xa in a $ye= xa end puts $ye #Look here. p $ye b.each do |bx| $bu = bx puts $ye #And look here. if $ye == $bu puts "#{$ye} and #{$bu}" end end Harry -- A Look into Japanese Ruby List in English http://www.kakueki.com/ruby/list.html