From: Caleb Clausen Date: 2006-07-28T01:49:59+09:00 Subject: Re: Symbols are your friends On 7/27/06, Daniel Schierbeck wrote: > Yes, it's time for another Symbol trick! > > class Symbol > def ===(obj) > obj.respond_to? "to_#{self}" > end > end This idea has been discussed on this list before; I can't find the thread at the moment. This seems like a really clever idea, and is fine for just playing around... but it's not advisable for general use. You're changing the semantics of Symbol#===, which will break things like this: case method_name when :reverse #.... when :each #... else #..... end The following is a simplified extract of what I use in Reg for a similar feature. It's safer, as long as nothing else decides to do something with Symbol#-@. class Symbol def -@; Reg::Knows.new(self) end end module Reg class Knows def initialize(sym) @sym=sym end def ===(other) other.respond_to? @sym end end end (You're prepending "to_" to your method names before checking; I don't know why. This way seems more general....)