On Wed, 21 Feb 2007, Chris Gallagher wrote:

> Hi,
>
> Im looking for a way of checking whether a method has returned true or
> false.
>
> for example i have an want to start off by checking if an image is already
> stored locally by calling " def checkCache". If the image is already there
> it will simply come back the process is complete. If it isnt there already
> it will need to call another method which will be called "downloadImage".
>
> What I have for this at the moment is far from complete so feel free to
> change it around:
>
>
> def index
>
> @domains = ['yahoo.com','google.com']
> domains_length = @domains.length
>
>    domains_length.times { |i|
> ######## if checkCache finds that there is no image present then it
> needs to        #########proceed to the next  method which would be
> downloadImage.
>       checkCache(@domains[i])
>       downloadImage(@domains[i])
>      end
>
>    }
> end
>
> def checkCache
>
> ....
> ....
>
> end
>
> def downloadImage
>
> ....
> ....
>
> end
>
> Please help me out on this one, I'm a little bit lost. If the question
> seems a bit vague or crazy please say so..

i'd use something like

   def unless_cached pathname
     yield unless File.exist?(pathname)
   end

   def download
   end

   domains.each do |domain|
     unless_cached(domain) do
       download
     end
   end

regards.

-a
-- 
we can deny everything, except that we have the possibility of being better.
simply reflect on that.
- the dalai lama