From: Benoit Daloze Date: 2010-07-08T02:01:50+09:00 Subject: Re: Ruby switches On 7 July 2010 17:18, Martin DeMello wrote: > class User >  attr_accessor :banned > >  def banned? >    banned >  end > >  def active? >    not banned >  end > end > > class Symbol >  def ===(other) >    other.send(self) >  end > end > > a = User.new > a.banned = true > > case a > when :banned? ; puts "banned!" > when :active? ; puts "active!" > end > > a.banned = false > > case a > when :banned? ; puts "banned!" > when :active? ; puts "active!" > end > > martin > Quite cool the Symbol#===, it made me think to Proc#=== Sadly, Proc need always a method to be created (so &:sym can not be used directly) But I found a (convoluted) example to use Proc#=== #encoding: utf-8 alias :ė :lambda def check(user) case user when ė(&:banned?) puts "Banned !" when ė(&:active?) puts "This is over-convoluted, but you're fine!" end end user = User.new user.banned = true check user user.banned = false check user