Reputation: 1700
I have an array of links:
urls =
[
["http://s3.amazonxaws.com/bb_images/uk/media_images/2/1-veXRiLqrxPbguaxFIcFbPA.png"],
["http://s3.amazonaws.com/bb_images/uk/media_images/2/1-veXRiLqrxPbguaxFIcFbPA.png"]
]
How can I return true
if all links start with "http://s3.amazonaws.com"
?
I tried:
if urls.any? { |url| url.include?('http://s3.amazonaws.com/') }
#execute code
else
#execute else code
end
But it does not return true
or false
in cases.
Upvotes: 2
Views: 687
Reputation: 4533
@sawa's code works. However, the following is a more efficient version.
compare_against = "http://s3.amazonaws.com"
urls.all?{|url_array| url_array[0].start_with?(compare_against)}
Upvotes: 4