配列を昇順でソートし、配列から値を選択して新しい配列に入れるのに問題があります。
# Splitting dance scores with "," and putting into arrays.
for dancers in results
a = dancers.split(",")
couplenumber = a[0]
score1 = a[1]
score2 = a[2]
score3 = a[3]
score4 = a[4]
score5 = a[5]
score6 = a[6]
score7 = a[7]
dancescores << Dancer.new(couplenumber, score1, score2, score3, score4, score5, score6, score7)
# Sorts the array into ascending order, and shows the 4 lowest values.
#p dancescores.sort.take(4)
# Getting the m value, from picking the 4th lowest number.
m = a[4]
newtest = [couplenumber, m]
coupleandscore << newtest
coupleandscore
end
puts coupleandscore
現在、新しい配列の元の値が得られます。しかし、私がやろうとすると
p dancescores.sort.take(4)
次のエラーが表示されます。
[#<Dancer:0x10604a388 @score7=5, @score3=3, @score6=6, @score2=2, @score5=1, @score1=1, @couplenumber="34", @score4=3>]
examtest.rb:43:in `sort': undefined method `<=>' for #<Dancer:0x10604a388> (NoMethodError)
どんな種類の助けも大歓迎です!