From: Robert Klemme Date: 2009-12-01T03:50:06+09:00 Subject: Re: if statement modifier, with else, warning On 30.11.2009 19:09, Gary Hasson wrote: > 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? It's a syntax error because of the ambiguity: robert@fussel ~ $ allruby -ce 'puts 1 if 2 > 0 else puts 3' ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin] -e:1: syntax error, unexpected kELSE, expecting $end puts 1 if 2 > 0 else puts 3 ^ ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-cygwin] -e:1: syntax error, unexpected keyword_else, expecting $end puts 1 if 2 > 0 else puts 3 ^ Btw, I believe you might have another issue in your code because of the precedence of "or". It might be safer to use "||" or proper bracketing. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/