Ruby 我们可以使用';除非';用红宝石?

Ruby 我们可以使用';除非';用红宝石?,ruby,Ruby,在ruby中,我们可以做如下事情 unless something do_this else do_that end 如果你愿意,我们也可以写其他的 unless something do_that elsif something_else do_this end 但是我们能写一些像这样的东西吗 if something do_this else unless something_else do_that end 当然,简单的解决方案是使用运算符。否。在这种情况下

在ruby中,我们可以做如下事情

unless something
  do_this
else 
  do_that 
end
如果你愿意,我们也可以写其他的

unless something
 do_that
elsif something_else
 do_this 
end 
但是我们能写一些像这样的东西吗

if something
 do_this
else unless something_else
 do_that
end 

当然,简单的解决方案是使用
运算符。

否。在这种情况下,您需要另一个嵌套级别

if something
  ...
else
  unless something_else
    ...
  end
end

原因可能是
else
+
,除非
太复杂。

否。在这种情况下,您需要另一个嵌套级别

if something
  ...
else
  unless something_else
    ...
  end
end

原因可能是
else
+
,除非
太复杂。

elsif呢!一般来说,避免使用
,除非(:p)你只有主句。我完全同意你的看法:)我只是好奇。。在大多数情况下,我只在后缀形式中使用它。关于
elsif!一般来说,避免使用
,除非(:p)你只有主句。我完全同意你的看法:)我只是好奇。。在大多数情况下,我只使用后缀形式