On Thu, 30 Sep 2004 16:50:03 +0900, Robert Klemme <bob.news / gmx.net> wrote: > > "Ralf M?ller" <r_mueller / imp-ag.de> schrieb im Newsbeitrag > news:2s1qktF1cjkj8U1 / uni-berlin.de... > > > > Salve! > > > > Is it possible in the 'when'-part to access components or mthods of an > > object specified in after 'case' ? > > > > Something like: > > > > case object > > when object.method == 'whatever' then ... > > when ohject.id%2 == 0 then ... > > end > > You can do > > case > when object.method == 'whatever' then ... > when ohject.id%2 == 0 then ... > end > > Note the subtle difference. :-) > > Alternatively you can define a criterion like this: > > crit1 = lambda {|x| x.method == 'whatever'} > class <<crit1; alias :=== :call end > > case object > when crit1; ... > when crit2; ... > end This sounds like a use case for the Proc.new extension proposal in the latest ruby-dev summary... To quote: > Nowake proposed that a Proc object should be invoked with > any method name like that: > >? ? ? ?m = Proc.new( :to_s ) { 'test1' } >? ? ? ?p m.to_s ? # => 'test1' So your code could be: crit1 = Proc.new(:===){|x| x.method === 'whatever'} case object when crit1 end Hmmm... I didn't like the idea before, but I might be changing my mind. cheers, Mark > > Kind regards > > robert > >