Aleksi Niemel<aleksi.niemela / cinnober.com> writes: > I got an idea for enhancing (?) case-when. Now 'when' actually forces the > use of '==='. What if not? > > case {|ancestor| obj.ancestors.include? ancestor} > when Foo > puts "Hey we have a Foo descendant here." > when Bar > puts "Blaahr." > end Well, you can do something (almost) equivalent in standard Ruby--you can associate closures with the 'when' conditions: # This is the code behind the curtains class When def initialize(aCheck) @check = aCheck end def ===(thing) @check.call(thing) end end def check(&proc) When.new(proc) end # Let's try it in a simple case... [1, 3, 4, 6, 7, 8, 9 ].each do |number| case number when check {|n| n % 2 != 0 && n % 3 != 0 } puts "#{number} is prime < 10" when check {|n| n & 1 == 1} puts "#{number} is odd" when check {|n| n & 1 == 0} puts "#{number} is even" else puts "#{number} is unknown" end end Regards Dave