Check if string contains any substring in an array in Ruby

后端 未结 5 1515
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-28 12:25

I am using the Tmail library, and for each attachment in an email, when I do attachment.content_type, sometimes I get not just the content type

5条回答
  •  眼角桃花
    2020-12-28 12:55

    If image/jpeg; name=example3.jpg is a String:

    ("image/jpeg; name=example3.jpg".split("; ") & VALID_CONTENT_TYPES).length > 0
    

    i.e. intersection (elements common to the two arrays) of VALID_CONTENT_TYPES array and attachment.content_type array (including type) should be greater than 0.

    That's at least one of many ways.

提交回复
热议问题