你有什么建议让这个if条件更短(更优雅)吗?
if (@path.start_with? "scp" || @path.start_with? "http")
@source = "url"
else
@source = "local"
end
Run Code Online (Sandbox Code Playgroud)
如果我有更多的前缀要检查(让我们说ftp1,ftp2和ftp3)怎么办?
start_with? 可以将多个字符串作为参数
@source = @path.start_with?("scp", "http") ? "url" : "local"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
58 次 |
| 最近记录: |