From: Dave Thomas Date: 2002-02-14T01:11:39+09:00 Subject: Re: qualms about respond_to? idiom David Alan Black writes: > All tags respond to tagStart? and tagEnd? But not all events in my > stream are tags. So.... > > if e.respond_to? :tagStart? > context.push(e.name) if e.tagStart? > end > > is my way of testing, first, whether it's a tag (but without actually > checking whether it's a tag), and, second, whether it's a start tag. A polymorphic way of doing this is to move responsibility down to the stream elements. Say each had a method handle_stack. Then your main code could simply call handle_stack on _all_ tags: e.handle_stack(context) start tags would have def handle_stack(stack) stack.push(name) end end tags might have (I'm guessing - I don't know what your app does here) def handle_stack(stack) top = stack.pop raise "Havoc!" unless top == name end and all other tags would have a null handle_stack def handle_stack(stack) end Dave