3
我读Ruby class inheritance: What is `<<` (double less than)?。我知道它有助于为实例创建方法(类型的继承)。但我碰到一个代码:
threads << Thread.new(page) { |myPage|
h = Net::HTTP.new(myPage, 80)
puts "Fetching: #{myPage}"
resp, data = h.get('/', nil)
puts "Got #{myPage}: #{resp.message}"
}
其中threads
是一个数组。有人可以用对象而不是类来解释<<
的用法吗?
将<< <<追加到数组中。所以一个新的'Thread'对象被添加到'threads'数组中。 –