我試圖更好地理解涉及EventMachine的以下幾行代碼。努力學習Ruby是一種艱辛的方式。EventMachine和一些Ruby語法
EventMachine.run在這段代碼中做了什麼?
什麼| chunk |在這種情況下呢?
另外,'while line'會做什麼?是行Ruby語法?我似乎無法找到與此相關的任何內容。
#create an HTTP request ob to URL above with user authorization
EventMachine.run do
http = EventMachine::HttpRequest.new(url).get :head => { 'Authorization' => [ user, password ] }
# Initiate an empty string for the buffer
buffer = ""
# Read the stream by line
http.stream do |chunk|
buffer += chunk
while line = buffer.slice!(/.+\r?\n/) #cut each line at newline
handle_tweet JSON.parse(line) #send each tweet object to handle_tweet method
end
end
end
你應該學習一些ruby語言的基礎。 WikiBooks中的[Ruby Tutorial](http://en.wikibooks.org/wiki/Ruby_Programming)可能會有所幫助。 – Flexoid
這就是我想要做的。 thx爲鏈接。 – fokusfocus