配列またはハッシュを反復処理しており、インデックスに基づいて値を取得したいと考えています。
@lv = {'apple' => ['round', 'red'], 'more names' => ['tags', 'more tags']}
@lv.each do |key, value|
# if the value is from the index key and equal to key itself...
end
から値を取得する方法がわかりません@lv
。私が取得したいとしましょうapple
:
@lv[0]
アップルと等しいはずのようなものはありますか?なぜなら
[0] => apple
[1] => more names
右?
だから私はできる
@lv.each do |key, value|
if @lv[0] == key
# apple equals apple, then proceed
end
end
これを行う際の正しい構文は何ですか?
ありがとう!