[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Checking what a method has returned

Chris Gallagher

2/21/2007 12:11:00 AM

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

Cheers,

Chris

--
Posted via http://www.ruby-....

6 Answers

Chris Gallagher

2/21/2007 1:52:00 AM

0

well the reason im doing this is for refoactoring purposes so my code is
chaning a lot.

What I have at the moment is:

file = 'public/images/' + source_url + '.jpg'
if ((FileTest.exists?(file))&&((Time.new-File.stat(file).mtime)<
50000))



..................

Im guessing I can stick a 'return true' just below that or does it work
that way?

--
Posted via http://www.ruby-....

Prime

2/21/2007 2:11:00 AM

0

I do not know if this will help you out, I think this is what you
wanted. This only calls the downloadImg method if the file exists.


@domains = ['yahoo.com','google.com']

def checkCache(filename)
if File.exists?(filename)
return true
else
return false
end
end

def downloadImg(name)
puts "called the download function"
end

@domains.each do |domain|
if checkCache(domain)
downloadImg(domain)
end
end



On 2007-02-20 17:51:48 -0800, Chris Gallagher <cgallagher@gmail.com> said:

> well the reason im doing this is for refoactoring purposes so my code is
> chaning a lot.
>
> What I have at the moment is:
>
> file = 'public/images/' + source_url + '.jpg'
> if ((FileTest.exists?(file))&&((Time.new-File.stat(file).mtime)<
> 50000))
>
>
>
> .................
>
> Im guessing I can stick a 'return true' just below that or does it work
> that way?


dblack

2/21/2007 2:20:00 AM

0

Chris Gallagher

2/21/2007 2:26:00 AM

0

thanks for the reply. The thing is that im not just checking the
existance of the file. the condition is that the file must exist and
also be less than x ammount of time old as seen in the if statement
above.



file = 'public/images/' + source_url + '.jpg'
if ((FileTest.exists?(file))&&((Time.new-File.stat(file).mtime)<
50000))

cheers,

chris

--
Posted via http://www.ruby-....

Ara.T.Howard

2/21/2007 2:28:00 AM

0

dblack

2/21/2007 2:24:00 PM

0