除非条件与 || 一起使用,否则我对 Ruby 如何使用感到困惑。操作员。
所以我基本上得到的是:
<% unless @instance_variable.method || local_variable.another_method %>
code block
<% end %
目前,第一部分评估为假,第二部分评估为真。而且我没有收到错误,它可以满足我的要求。但是,如果我只写:
<% unless @instance_variable.method %>
code block
<% end %>
我收到一个错误,当我写时我收到一个错误:
<% unless @instance_variable.method && local_variable.another_method %>
code block
<% end %>
所以我的问题。如果第一部分评估为假,它会缩短并通过代码块,而不是看另一边吗?如果是这样,为什么留下第二部分会引发错误?这一切如何运作?
抱歉,如果您需要代码,我觉得这是一个逻辑/代数解决方案。