Bug #13879

Updated by nobu (Nobuyoshi Nakada) over 5 years ago


 I am not sure if the following is a bug or a feature. 


     x = 'foobar' 
     case x 
     when 'a','b','c', 
       x = 5 
     puts x 

 Works fine. 

 But this here: 


     x = 'foobar' 
     case x 
     when 'a','b','c', 
       puts 5 

 Leads to this error: 

     syntax error, unexpected tINTEGER, expecting keyword_do or '{' or '(' 

 Is this deliberately so? My confusion is that case/when works fine 
 in one case, but leads to an error in another case. I am not 
 sure if it is a bug or not, but I believe in the first case, 
 the user may have not wanted to put a trailing ',' there and 
 simply forgot to remove it. That is actually how I found out about 
 this behaviour, since I have a huge case/when menu and sometimes 
 make typos when re-arranging entries, including such trailing ',' 
 via copy/paste jobs. :) 

 If it is a bug then perhaps it can be fixed; if it is not a 
 bug, perhaps the official documentation could explain this 
 feature? Or perhaps if trailing ',' are not useful, there 
 may be a warning issued or something in the first case. 

 Anyway, I am just reporting this in case nobody knows about  
 this - feel free to close this issue at any moment in time.