H
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 `<top (required)>'
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?
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 `<top (required)>'
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?