我有這樣的代碼Ruby中未定義的方法'pop'?
def longest_word(sentence)
long_word = ""
sentence.split(" ").sort_by {|x| x.length}
long_word = sentence.pop
return long_word
end
p longest_word("hello dogs are fast")
我也得到了該方法「流行」是不確定的,當我嘗試運行它的錯誤。這是否與gemfiles有關?我以爲我已經設置了這些東西。