From: Daniel Schierbeck Date: 2006-07-28T23:40:10+09:00 Subject: Re: Weird problem with case expressions dblack@wobblini.net wrote: > Hi -- > > On Fri, 28 Jul 2006, Daniel Schierbeck wrote: > >> I have no problem doing this: >> >> if foo :bar then >> ... >> end >> >> Yet when I do this: >> >> case "foo" >> when bar :baz then "bur" >> end >> >> I get the following syntax error: >> >> SyntaxError: compile error >> (irb):30: parse error, unexpected tSYMBEG, expecting kDO or '{' or '(' >> when bar :baz then "bur" > > I guess when binds more tightly than a parentheses-less method call. > You could do: > > when bar(:baz) ... Thank you for the response. Yes, it seems there is no way to get around using parentheses. It's actually just an aesthetic problem; the method in question has a question mark suffix, and I like to call such methods without parentheses. Specifically, it was an attempt at an aesthetically pleasing version of the code in "Symbols are your friend": case "foo" when of_type? :int then "integer" when of_type? :str then "string" end Unfortunately, I'll have to write it like this: case "foo" when of_type?(:int) then "integer" when of_type?(:str) then "string" end It doesn't really matter that much though -- I'm not even sure I like that solution. Cheers, and thanks for replying, Daniel