A funny (and readable) way to test collection sizes just occurred to me:
irb(main):001:0> class Integer
irb(main):002:1> def elements
irb(main):003:2> cond = lambda {|enum| self == enum.size}
irb(main):004:2> class <<cond
irb(main):005:3> alias :=== :call
irb(main):006:3> end
irb(main):007:2> cond
irb(main):008:2> end
irb(main):009:1> end
=> nil
irb(main):010:0> case [1,2,3]
irb(main):011:1> when 3.elements
irb(main):012:1> puts “three!”
irb(main):013:1> when 5.elements
irb(main):014:1> puts “too much!”
irb(main):015:1> else
irb(main):016:1* puts “else”
irb(main):017:1> end
three!
=> nil
Kind regards
robert