The following statement works fine, even though it generates a warning.
With regard to “if” and “unless” being used as statement modifiers, a
manual states: “Obviously, this syntax does not allow any kind of else
clause.”
compare_files unless @filename_1 == nil or @filename_2 == nil else @messagetextctrl.append_text(" ==> Please specify files to compare.
\n")
Error Msg: “…rb:112: warning: else without rescue is useless”
Obviously, the statement can be changed to the normal “if-else-end”
format, but that would not be as Ruby-ish as the above approach.
Is there a good reason why Ruby should not allow “else” to be used as in
the example above?
The following statement works fine, even though it generates a warning.
With regard to “if” and “unless” being used as statement modifiers, a
manual states: “Obviously, this syntax does not allow any kind of else
clause.”
compare_files unless @filename_1 == nil or @filename_2 == nil else @messagetextctrl.append_text(" ==> Please specify files to compare.
\n")
Error Msg: “…rb:112: warning: else without rescue is useless”
Obviously, the statement can be changed to the normal “if-else-end”
format, but that would not be as Ruby-ish as the above approach.
What would be un-Rubyish about not using the statement modifier? The
normal syntax would be far clearer here.
Is there a good reason why Ruby should not allow “else” to be used as in
the example above?
Because it would lead to confusing code. Statement modifiers are fine
for the simplest cases, but toss in any complexity and you’ve got chaos.