update: sorry, I fixed my program:
a = [ 'str1' , 'str2', 'str2', 'str3' ]
name = ''
a.each_with_index do |x, i |
if x == name
puts "#{x} found duplicate."
else
puts x
name = x if i!= 0
end
end
output:
str1
str2
str2 found duplicate.
str3
Is there another beautiful way in ruby
language to do the same thing ?
btw, actually. a
is a ActiveRecord::Relation
in my real case.
Thanks.