From: Gregory Brown Date: 2008-08-02T06:09:22+09:00 Subject: Re: Help finding this syntax error On Fri, Aug 1, 2008 at 5:06 PM, Gregory Brown wrote: > On Fri, Aug 1, 2008 at 4:53 PM, Patrick Li wrote: >> Hmm that makes more sense. >> But now i'm confused why my code worked after removing the outside >> parenthesis. >> >> when i type this: >> if FieldTypes.key? field && FieldTypes[field].respond_to? :select >> >> shouldn't ruby be seeing this? >> if (FieldTypes.key? field && FieldTypes[field].respond_to?) :select >> >> which is still a syntax error? >> >> Am i calculating what i think i'm calculating? > > No idea. Adapting your code a bit but using a similar syntax: This all having been said, the point of leaving off parens is to make your code clearer to read in places. Having to understand esoteric parsing rules does not contribute to that, so the way I'd suggest writing this is: if FieldTypes[field].respond_to? :select since the key? check isn't really doing anything for you. A key won't be autovivified, and Nil does not respond to select, >> a = {} => {} >> a[:foo] => nil >> a => {} >> nil.respond_to?(:select) => false Or if you prefer to leave it at is, just use normal parens: if FieldTypes.key?(field) && FieldTypes[field].respond_to?(:select) People will thank you for the extra 4 chars. :) -greg -- Killer Ruby PDF Generation named after a magnificent sea creature: http://github.com/sandal/prawn | Non-tech stuff at: http://metametta.blogspot.com