On 10.06.2007 14:15, Robert Dober wrote:
> 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

I am not sure whether utility of define_casey is fully clear to me yet - 
so I leave it to you to write the RCR. :-)

But I do think you're getting the hang of Ruby. :-)

Kind regards

	robert