Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
problem with .each do
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Lloyd Zusman, post: 4493112"] It turns out that Net::Http#get no longer returns a pair of values. It has changed between ruby version 1.6 (from the edition of the book that you probably have) and 1.8. This is explained in the method's latest documentation (from [URL]http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html[/URL]): get(path, initheader = nil, dest = nil) {|+body_segment+| ...} Gets data from path on the connected-to host. header must be a Hash like { 'Accept' => '*/*', ... }. In version 1.1 (ruby 1.6), this method returns a pair of objects, a Net::HTTPResponse object and the entity body string. In version 1.2 (ruby 1.8), this method returns a Net::HTTPResponse object. If called with a block, yields each fragment of the entity body in turn as a string as it is read from the socket. Note that in this case, the returned response object will not contain a (meaningful) body. dest argument is obsolete. It still works but you must not use it. In version 1.1, this method might raise an exception for 3xx (redirect). In this case you can get a HTTPResponse object by "anException.response". In version 1.2, this method never raises exception. # version 1.1 (bundled with Ruby 1.6) response, body = http.get('/index.html') # version 1.2 (bundled with Ruby 1.8 or later) response = http.get('/index.html') # using block File.open('result.txt', 'w') {|f| http.get('/~foo/') do |str| f.write str end } See also Net::HTTPResponse within that same documentation. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
problem with .each do
Top