From: Robert Dober Date: 2007-06-10T21:15:35+09:00 Subject: Re: fun with "case" Sorry forgot the best ;) class Object def identity; self end # I wanted this for a long time, maybe itself would be a good name too end class Module def define_casey opts={} arg_mth = opts[:on] name = opts[:name] trans = opts[:transform] define_method name do | *args | cond = lambda{ |x| trans ? self.send(trans, *args) == x.send( arg_mth ) : self == x.send( arg_mth ) } class << cond alias_method :===, :call end cond end end end class Integer define_casey :on => :size, :name => :elements define_casey :on => :identity, :name => :plus, :transform => :+ end case [] when 0.elements puts :empty end case 42 when 41.plus( 1 ) puts "The number" end Robert