如何使用Ruby压缩语句中的多相同条件?

问题描述 投票:2回答:2

这是我所做的:

output = "xyz"
result = false

unless output == "" || output.nil? || output == "{}" || result == true
  puts 'execute this command'
end

如果Ruby中存在类似的||条件,那么收缩上述语句的最简单格式是什么?>

这是我所做的:输出=“ xyz”结果= false,除非输出==“” || output.nil? ||输出==“ {}” ||结果== true将“执行此命令”放在末尾。...

ruby
2个回答
1
投票

这样的事情?


1
投票

在较新版本的Ruby中,您有使用吗?这样:

© www.soinside.com 2019 - 2024. All rights reserved.