In Ruby, how do I find out if a string is not in an array?

前端 未结 5 1835
北荒
北荒 2021-01-01 08:44

In Ruby, how would I return true if a string is not in an array of options?

# pseudo code
do_this if current_subdomain not_in [\"www\", \"blog\", \"foo\", \"         


        
5条回答
  •  轮回少年
    2021-01-01 09:25

    You can try exclude? method instead of include?

    Example:

    do_this if ["www", "blog", "foo", "bar"].exclude?(current_subdomain)
    

    Hope this help...Thanks

提交回复
热议问题