Reputation: 2916
I am trying to check for images src in a HTML img tag using following code
extension.end_with?(/[.jpg|.gif|.png|.jpeg]/).should eq(true)
where extension = "teaser_image610x450.jpg"
I also tried
extension.end_with?(/[.]jpg|gif|png|jpeg/).should eq(true)
In both cases I am getting FALSE. What is wrong with above code ?
Upvotes: 1
Views: 249
Reputation: 96827
You can use the following form:
extension.end_with?(".jpg",".gif",".png",".jpeg")
Or, something like this:
extensions = [".jpg",".gif",".png",".jpeg"]
if extensions.include?(extension)
# do something here
end
I never saw this method being used with a regex before.
Upvotes: 2