<posted & mailed> Richard Dale wrote: > > Are there any rules of thumb for when it's a good idea to leave out the > brackets and when to use them? I'm trying to retrain myself to _never_ omit the parentheses around argument lists. It's tough - I like "poetry mode" - but I think the parens make the code easier to read. Your example is a perfect illustration. > > He says it's bad style to use 'if c.kind_of? Elephant', and instead it's > better to expect each node to return a number of elephants. His improved > example expects every node to respond to 'num_elephants', but he makes no > check and so there would be a method_missing execption thrown for a > non-elephant/non-box thing. > > I think the second example would be improved by a respond_to? check, but > what if you expected 'elephant aware nodes' to return you a total elephant > weight? Has anyone suggested adding a 'conforms_to?' check in ruby that > checks that an instance will respond_to? an Array of method name symbols? > Frequently. Google comp.lang.ruby for 'duck typing' and be prepared for a lot of reading. Warning: it's a divisive topic.