我试图更好地理解涉及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