From: Robert Klemme Date: 2011-06-28T21:57:45+09:00 Subject: Re: Symbol#=== On Sat, Jun 25, 2011 at 9:15 PM, Intransition wrote: > > > On Jun 25, 1:00 pm, Robert Dober wrote: >> On Sat, Jun 25, 2011 at 7:57 AM, Intransition wrote: >> > As: >> >> >    class Symbol >> >      def ===(object) >> >        object.respond_to?(self) >> >      end >> >    end >> >> > Then: >> >> >    case foo >> >    when :some_method >> >      foo.some_method >> >    end >> >> > Insanity? Maybe, maybe not... The two of me can't really agree... :-) >> No, but too invasive... >> >> case my_token >> when :integer >> when :identifier >> when.... >> >> thanx for breaking that ;) > > lol. let me "fix" it for you > >    class Symbol >      def ===(object) >        return super(object) if Symbol === object >        object.respond_to?(self) >      end >    end > > Of course, now no repsond_to? case checking for Symbols! I'd rather keep this simpler: class Symbol def ===(o) equal? o or o.respond_to? self end end irb(main):012:0> :s === :s => true irb(main):013:0> :length === "foo" => true irb(main):014:0> :nono === "bar" => false >> Furthermore I already feel that Symbol has one of the worst kludges >> ever conceived cast onto itself, which is #to_proc. On the same >> account I feel #=== should not be concerned with receiver's methods. > > #to_proc that bad? No, I like it. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/