with a string like : subpart.content_type = "video/mp4; name=tom1- short.mp4" is there anyway to avoid a loop in checking if this string contains one of the extension in an array [''mp4'', ''m4v'', ''mov''] something like : subpart.content_type.include_one_of_them? [''mp4'', ''m4v'', ''mov''] thanks for you suggestions erwin I can make it work but I have to write a loop -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-Feb-09 12:38 UTC
Re: coding a string.include? any_item_in[array] to avoid a loop
On 9 February 2011 12:29, Erwin <yves_dufour-ee4meeAH724@public.gmane.org> wrote:> with a string like : subpart.content_type = "video/mp4; name=tom1- > short.mp4" > is there anyway to avoid a loop in checking if this string contains > one of the extension in an array [''mp4'', ''m4v'', ''mov''] > > something like : > > subpart.content_type.include_one_of_them? [''mp4'', ''m4v'', ''mov'']You can use a regular expression. Google ruby regular expressions if you do not know how. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.