我基本上是在寻找一种更漂亮的方式来写:
do_something() if my_string == 'first' | my_string == 'second' | my_string == 'third'
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
最常见的解决方案是使用Array#include?:
do_something if %w(first second third).include? my_string
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
863 次 |
| 最近记录: |