The program should produce only unique aircraft, it repeats the element array. uniq method doesn't help.
class Airplane
attr_accessor :model
def initialize(model)
@model = model
end
end
models = [ "Boeing 777-300ER",
"Boeing 737-800",
"Airbus А330-200",
"Airbus А330-300",
"Airbus А321",
"Airbus A320",
"Sukhoi SuperJet 100"]
planes = []
150.times do
model = models[rand(0..6)]
plane = Airplane.new(model)
planes << plane
try here # planes = planes.uniq doesn't help
break if models.length == planes.length
end
# result
planes.uniq.each do |plane| # <<<< uniq doesn't help
puts "Model: #{plane.model}"
end
uniqis called on the 150-element array ofAirplane, not on the 7-element array ofString. The issue is the lack of equality predicate onAirplaneclass.Airplane#eql?being the first problem.