在Ruby中,如果字符串不在选项数组中,如何返回true?
# pseudo code
do_this if current_subdomain not_in ["www", "blog", "foo", "bar"]
...或者你知道有更好的方法写这个吗?
在Ruby中,如果字符串不在选项数组中,如何返回true?
# pseudo code
do_this if current_subdomain not_in ["www", "blog", "foo", "bar"]
...或者你知道有更好的方法写这个吗?
do_this unless ["www", "blog", "foo", "bar"].include?(current_subdomain)
或
do_this if not ["www", "blog", "foo", "bar"].include?(current_subdomain)
I'm using the Array#include? method.
然而,使用unless
是一个相当大的ruby习惯用法.