# Strange NoMethodError

**URL:** <https://www.ruby-forum.com/t/strange-nomethoderror/101712>\
**Category:** Ruby\
**Created:** [August 7, 2006, 4:33pm UTC](https://www.ruby-forum.com/t/strange-nomethoderror/101712 "2006-08-07T16:33:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Holger\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/898d66/32.png) [@Holger\_B](https://www.ruby-forum.com/u/Holger_B)\
**Post date:** [August 7, 2006, 4:33pm UTC](https://www.ruby-forum.com/t/strange-nomethoderror/101712/1 "2006-08-07T16:33:36Z")

</div>

Hi,  
In the following test script (similar to pickaxe p. 700 ):

require ‘net/http’  
require ‘uri’

def fetch (uri\_str, limit=10)  
fail ‘http redirect limit exceeded’ if limit.zero?  
response = Net::HTTP.get\_response(URI.parse(uri\_str))  
case response  
when Net::HTTPSuccess  
response  
when Net::HTTPRedirection  
fetch(response[‘location’], limit-1)  
else  
response.error!  
end  
end

fetch(‘[heise.de](http://heise.de)’);

with  
ruby test.rb  
I get the result:

Exception `NoMethodError’ at /usr/local/lib/ruby/1.8/net/http.rb:380

- undefined method `request_uri' for #<URI::Generic:0x188f84 URL:heise.de> /usr/local/lib/ruby/1.8/net/http.rb:380:in `get\_response’: undefined  
method `request_uri' for #<URI::Generic:0x188f84 URL:heise.de> (NoMethodError) from /usr/local/lib/ruby/1.8/net/http.rb:545:in `start’  
from /usr/local/lib/ruby/1.8/net/http.rb:379:in `get_response' from test.rb:6:in `fetch’  
from test.rb:18

I had a look at /usr/local/lib/ruby/1.8/uri/http.rb  
The function was defined there:

# 

```
 # == Description
 #
 # Returns: path + '?' + query
 #
 def request_uri
   r = path_query
   if r[0] != ?/
     r = '/' + r
   end

   r
 end

```

It should be a function of the standard libray. I am quite new to  
ruby. How can I debug this problem? Or any hints what I can do?

Thanks in advance for your help,

Holger

---

<div class="post-metadata">

**Author:** ![Holger\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/898d66/32.png) [@Holger\_B](https://www.ruby-forum.com/u/Holger_B)\
**Post date:** [August 7, 2006, 5:03pm UTC](https://www.ruby-forum.com/t/strange-nomethoderror/101712/2 "2006-08-07T17:03:41Z")

</div>

On Mon, 7 Aug 2006, Holger B. wrote:

> when Net::HTTPSuccess  
> response  
> when Net::HTTPRedirection  
> fetch(response[‘location’], limit-1)  
> else  
> response.error!  
> end  
> end
> 
> fetch(‘[heise.de](http://heise.de)’);  
> ^^^^^^^^  
> ^^^^^^^^

this is not a uri.

try

harp:~ \> ruby -r uri -e’ p URI.parse(“[heise.de](http://heise.de)”).host ’  
nil

harp:~ \> ruby -r uri -e’ p URI.parse(“[http://heise.de](http://heise.de)”).host ’  
“[heise.de](http://heise.de)”

regards.

-a

---

<div class="post-metadata">

**Author:** ![Holger\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/898d66/32.png) [@Holger\_B](https://www.ruby-forum.com/u/Holger_B)\
**Post date:** [August 7, 2006, 8:52pm UTC](https://www.ruby-forum.com/t/strange-nomethoderror/101712/3 "2006-08-07T20:52:10Z")

</div>

On Aug 7, 2006, at 5:02 PM, removed\_email\_address@domain.invalid wrote:

> > response = Net::HTTP.get\_response(URI.parse(uri\_str))
> 
> harp:~ \> ruby -r uri -e’ p URI.parse(“[http://heise.de](http://heise.de)”).host ’  
> “[heise.de](http://heise.de)”
> 
> regards.
> 
> -a

Oh my god … thank you vey much. You are right. I was a it confused  
because of the NoMethodError and I thought I had installed something  
wrongly. Thanks for your hint 🙂

best regards,  
Holger
