각자에게 전달 된 블록 내에있는 for-loop 내에서 Ruby의 각 반복자로 돌아갈 수 있는지 궁금합니다.For 루프에서 각 반복자로 돌아 가기
def find member = ""
productHash = {}
#@entries is a hash, with both the keys and values being strings
#the member parameter is a string
@entries.each do |key, value|
for i in 0...member.size
if(key[i] != member[i])
next #the next keyword doesn't work...all it does is return to the for iterator. I'm looking for a keyword that would return to the each iterator, and allow each to pass back in the next key-value pair.
end
end
productHash[key] = value
end
productHash
end
는 내가 달성 노력하고있어 이것이다 : 나는 멤버 매개 변수에 문자가 지정된 키에 해당하는 문자를 일치하지 않음을 보는 순간, 나는 다음 키 - 값 쌍으로 이동 .
이 왜 루프를 사용하고 있습니까? 블록을 사용하여 각 방법을 사용하는 것이 어떻습니까? – jason328
@ jason328 어떻게 도움이 될까요? 이 문제는 여전히 내가 생각하는 것과 같을 것이다. 그리고 여기서 for 루프를 사용하는 이유는 매개 변수 "member"의 해당 문자와 비교할 목적으로 인덱스 번호를 추적 할 수 있기 때문입니다. 내 생각에 개념적으로 내 질문은 return 문 (break, next, return과 같은)이 for 루프 반복자와 각 반복자를 구분하는지 여부입니다. – voltair
질문을 이해하는 데 어려움을 겪고 있습니다. 'each_with_index'를 사용하면 도움이 될까요? – jason328