On 7 Apr 2009, at 12:18, Arun Kumar wrote:
> Hi Ellie,
> I once again thank you for your reply. It helped me a lot. Now I  
> want to
> share some doubt with you.
> 1) How can i specify the redirect limit without declaring it inside a
> method. Is it possible?

The redirect limit isn't declared inside the method but as one of the  
parameters of the method, which is why it allows recursive execution  
as each redirect is received. You'll note that I provided an initial  
value as part of the initial functional call:

	data = get_http_response(my_uri, 3).body

but in a real-world program you either specify a constant and use that:

	MAXIMUM_REDIRECTS = 3
	data = get_http_response(MAXIMUM_REDIRECTS, 3).body

or else wrap everything together into an object where this value would  
be either an instance or class variable depending on your intent.

> 2) By including a redirect limit, will I be able to make the code for
> url redirection the most effective one or should i include some  
> aditions
> to the code to handle redirection effectively?

I can't really answer that question without knowing more about the  
real-world problem you're trying to solve. However in general I'd say  
that whenever you have a recursive problem like this it's sensible to  
ensure that it's throttled to prevent resource exhaustion. For a very  
graphic example of why this is important - especially with network  
applications - read up on the Morris Worm :)


Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net
----
raise ArgumentError unless @reality.responds_to? :reason