"카운트"방법이 The string count() method에서 어떻게 작동하는지 알고 있습니다.루비에서 카운트가 어떻게 작동합니까?
하지만 그것은 배열에 (오히려 편지 쓰기보다) 단어를 계산 어떻게 이해할 수 없다 :
def find_frequency(sentence, word)
sentence.downcase.split.count(word.downcase)
end
find_frequency("to be or not to be", "to") # => 2
# same as ["to", "be", "or", "not", "to", "be"].count("to")
"hello world".count("lo") # => 5
"hello world".count("lo")
하면 반환 다섯, 왜하지 않습니다 find_frequency("to be or not to be", "to")
반환 칠 (t, 오, 오, 오, t, t, o)?
감사합니다! 특히 [apidock] (http://apidock.com)에 대한 링크. – Evgeny
여기에 가입 할 수 있습니까? - http://chat.stackoverflow.com/rooms/27184/ruby-conceptual? –