From: 7stud -- Date: 2012-12-11T06:00:10+09:00 Subject: Re: Array of a class' attribute Leo M. wrote in post #1088536: > > def erase_doubles > > @results.each do |result| > > #I REALLY DON'T HAVE IDEA ABOUT HOW TO BUILD IT :) > > end > class Result attr_accessor :name, :link, :messages def initialize(name, link, msg) @name = name @link = link @msg = msg end end links = ['a', 'b', 'a', 'c', 'c'] names = ["Joe", "Bob", "Cathy", "Doug", "Carol"] messages = ["mars", "venus", "jupiter", "mercury", "earth"] links_enum = links.each names_enum = names.each msg_enum = messages.each results = names.map do |link| Result.new(names_enum.next, links_enum.next, msg_enum.next) end p results --output:-- [#, #, #, #, #] hash = Hash.new { |h, k| h[k] = [] } results.each do |r| hash[r.link] = r end p hash.values --output:-- [#, #, #] -- Posted via http://www.ruby-forum.com/.