Help with IO Code

I’m working through “Programming Ruby - The Pragmatic
Programmer’s Guide” and all has been joy and pleasure.
Now, however, I’m in difficulty.

From the IO chapter I’m running the following example:

require ‘net/http’

h = Net::HTTP.new(‘www.pragmaticprogrammer.com’, 80)
resp, data = h.get(’/index.html’, nil)
puts resp.message #I added this
puts data #And this
if resp.message == “OK”
#Spam assasin didn’t like the Img tag in the re.
data.scan(/###/) { |x| puts x }
end

The result I’m getting is:

OK
nil
listimgs.rb:8: private method `scan’ called for nil
(NoMethodError)

The code should list the images on the pragprog home
page.

Any idea whats going wrong, or how I can find out more
about whats going wrong.

I’m using 1.8.0-9

···

Want to chat instantly with your online friends? Get the FREE Yahoo!
Messenger http://uk.messenger.yahoo.com/

resp, data = h.get('/index.html', nil)

Well, the problem is that Net::HTTP#get has changed between 1.6
("Programming Ruby") and your version of ruby 1.8

    # 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.

puts resp.message #I added this
puts data #And this

   puts resp.body

if resp.message == "OK"
  #Spam assasin didn't like the Img tag in the re.
  data.scan(/###/) { |x| puts x }

     resp.body.scan(/###/) { |x| puts x }
     

end

Guy Decoux

That’s an issue with the net/http code changing…
but I thought it had been resolved and a “compatibility”
fix had been added.

Suggest you search ruby-talk.org for messages in the
last 2-3 months about net/http – if you can’t find
the relevant ones, I’ll assist.

Hal

···

----- Original Message -----
From: “Ged Byrne” gedb01@yahoo.co.uk
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Friday, August 15, 2003 9:53 AM
Subject: Help with IO Code

I’m working through “Programming Ruby - The Pragmatic
Programmer’s Guide” and all has been joy and pleasure.
Now, however, I’m in difficulty.

From the IO chapter I’m running the following example:

require ‘net/http’

h = Net::HTTP.new(‘www.pragmaticprogrammer.com’, 80)
resp, data = h.get(‘/index.html’, nil)
puts resp.message #I added this
puts data #And this
if resp.message == “OK”
#Spam assasin didn’t like the Img tag in the re.
data.scan(/###/) { |x| puts x }
end

The result I’m getting is:

OK
nil
listimgs.rb:8: private method `scan’ called for nil
(NoMethodError)

Wow, you guys are fast!

Thanks. I’ll have this cracked in no time.

What API Referenece would you recommend? The
one-click installation comes with the “programming”
book.

···

— “Hal E. Fulton” hal9000@hypermetrics.com wrote:

----- Original Message -----
From: “Ged Byrne” gedb01@yahoo.co.uk
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Friday, August 15, 2003 9:53 AM
Subject: Help with IO Code

I’m working through “Programming Ruby - The
Pragmatic
Programmer’s Guide” and all has been joy and
pleasure.
Now, however, I’m in difficulty.

From the IO chapter I’m running the following
example:

require ‘net/http’

h = Net::HTTP.new(‘www.pragmaticprogrammer.com’,

resp, data = h.get(‘/index.html’, nil)
puts resp.message #I added this
puts data #And this
if resp.message == “OK”
#Spam assasin didn’t like the Img tag in the re.
data.scan(/###/) { |x| puts x }
end

The result I’m getting is:

OK
nil
listimgs.rb:8: private method `scan’ called for
nil
(NoMethodError)

That’s an issue with the net/http code changing…
but I thought it had been resolved and a
“compatibility”
fix had been added.

Suggest you search ruby-talk.org for messages in the
last 2-3 months about net/http – if you can’t find
the relevant ones, I’ll assist.

Hal


Want to chat instantly with your online friends? Get the FREE Yahoo!
Messenger http://uk.messenger.yahoo.com/

Wow, you guys are fast!

Thanks. I’ll have this cracked in no time.

What API Referenece would you recommend? The
one-click installation comes with the “programming”
book.

That’s probably still the best online reference.

You need “ri” if you don’t have it – it’s a
command-line based reference tool (also by
Dave Thomas).

Not sure if it’s bundled with 1.8, though if not,
it should be IMO. If you can’t find it, it is
probably on rubycentral.com or rubygarden.org
not sure where it “lives.” Hopefully it’s even
in the RAA.

I also have an (out of date) page “Ruby I/O at
a Glance” on rubyhacker.com if you want to look
at that.

Hal

···

----- Original Message -----
From: “Ged Byrne” gedb01@yahoo.co.uk
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Friday, August 15, 2003 11:19 AM
Subject: Re: Help with IO Code

— “Hal E. Fulton” hal9000@hypermetrics.com wrote:

----- Original Message -----
From: “Ged Byrne” gedb01@yahoo.co.uk
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Friday, August 15, 2003 9:53 AM
Subject: Help with IO Code

I’m working through “Programming Ruby - The
Pragmatic
Programmer’s Guide” and all has been joy and
pleasure.
Now, however, I’m in difficulty.

From the IO chapter I’m running the following
example:

require ‘net/http’

h = Net::HTTP.new(‘www.pragmaticprogrammer.com’,

resp, data = h.get(‘/index.html’, nil)
puts resp.message #I added this
puts data #And this
if resp.message == “OK”
#Spam assasin didn’t like the Img tag in the re.
data.scan(/###/) { |x| puts x }
end

The result I’m getting is:

OK
nil
listimgs.rb:8: private method `scan’ called for
nil
(NoMethodError)

That’s an issue with the net/http code changing…
but I thought it had been resolved and a
“compatibility”
fix had been added.

Suggest you search ruby-talk.org for messages in the
last 2-3 months about net/http – if you can’t find
the relevant ones, I’ll assist.

Hal


Want to chat instantly with your online friends? Get the FREE Yahoo!
Messenger http://uk.messenger.yahoo.com/