あなたの質問はうまく説明されていませんが、あなたが欲しいものの簡単な推測として、私はArray.group_by
Enumerableの一部であるを見るのをお勧めします:
ary = [
%w[3.0.1.2 TOTAL Pass],
%w[3.0.1.3 TOTAL Pass],
%w[3.4.0.1 8K Fail],
%w[3.5.4.3 9K Fail],
%w[3.5.0.9 TOTAL Fail],
]
ary.group_by{ |a| a.last }
これはハッシュを返します。キーはサブ配列の最後の要素の2つの異なる値です。
{
"Pass" => [
[0] [
[0] "3.0.1.2",
[1] "TOTAL",
[2] "Pass"
],
[1] [
[0] "3.0.1.3",
[1] "TOTAL",
[2] "Pass"
]
],
"Fail" => [
[0] [
[0] "3.4.0.1",
[1] "8K",
[2] "Fail"
],
[1] [
[0] "3.5.4.3",
[1] "9K",
[2] "Fail"
],
[2] [
[0] "3.5.0.9",
[1] "TOTAL",
[2] "Fail"
]
]
}
どちらかにアクセスするのは簡単です。
ary.group_by{ |a| a.last }['Pass']
[
[0] [
[0] "3.0.1.2",
[1] "TOTAL",
[2] "Pass"
],
[1] [
[0] "3.0.1.3",
[1] "TOTAL",
[2] "Pass"
]
]
または:
ary.group_by{ |a| a.last }['Fail']
[
[0] [
[0] "3.4.0.1",
[1] "8K",
[2] "Fail"
],
[1] [
[0] "3.5.4.3",
[1] "9K",
[2] "Fail"
],
[2] [
[0] "3.5.0.9",
[1] "TOTAL",
[2] "Fail"
]
]