From: hemant kumar Date: 2007-12-21T22:18:48+09:00 Subject: Re: Problem with case statements On Fri, 2007-12-21 at 18:47 +0530, hemant kumar wrote: > On Fri, 2007-12-21 at 21:01 +0900, Robert Klemme wrote: > > 2007/12/21, hemant kumar : > > > I have an innocent looking code: > > > > > > 54: def find(*args) > > > 55: options = args.extract_options! > > > 56: validate_find_options(options) > > > 57: case args.first > > > 58: when :first: find_first(options) > > > 59: when :all: find_all(options) > > > 60: else raise "Invalid find" > > > 61: end > > > 62: end > > > > > > > > > Now, above case statement totally blows up with Ruby 1.9: > > > > > > /home/hemant/push_server/lib/db_connection.rb:61: warning: else without > > > rescue is useless > > > /home/hemant/push_server/bin/boot.rb:34:in > > > `require': /home/hemant/push_server/lib/db_connection.rb:58: syntax > > > error, unexpected ':', expecting keyword_then or ',' or ';' or > > > '\n' (SyntaxError) > > > when :first: find_first(options) > > > ^ > > > /home/hemant/push_server/lib/db_connection.rb:59: syntax error, > > > unexpected keyword_when, expecting keyword_end > > > when :all: find_all(options) > > > ^ > > > /home/hemant/push_server/lib/db_connection.rb:87: syntax error, > > > unexpected keyword_end, expecting $end > > > from /home/hemant/push_server/bin/boot.rb:34:in `' > > > > Does the same error surface if you precede the colon with a space? > > Sorry, I don't have a 1.9 here to test this myself. > > > > > However if i rewrite it like this, it works: > > > > > > def find(*args) > > > options = args.extract_options! > > > validate_find_options(options) > > > case args.first > > > when :first > > > find_first(options) > > > when :all > > > find_all(options) > > > else > > > raise "Invalid find" > > > end > > > end > > > > > > Why is this? Was this intended? > > > > Maybe the form with colon is deprecated? > > > > Looks like they deprecated ":" in case statements. > > Matz, shall we consider this as bug or change was unintentional? My bad.. i meant intentional, but you got the point anyways!. Thanks