On Nov 26, 7:56=A0am, Diego Virasoro <diego.viras... / gmail.com> wrote:
> Hi all,
> I just wanted to share a couple of things I've found out lately. I
> imagine they are well known to the experts here, but I thought maybe
> there are other newbies out there that could benefit from it too.
>
> 1) Using proc in the case statement:
>
> I find the case statement particularly elegant: especially when
> there's a long list of choices I much prefer it to using if...
> elsif... else... end. That said the latter offers a lot more
> flexibility. Still a lot can be accomplished by using procs. For
> example:
>
> case val
> when Hash
> ...
> when lambda{|x| x.respond_to?(:to_ary) && x.length>1}

when proc{|x| x.respond_to?(:to_a) && x.size>1}

Using a Proc in this way doesn't work under Ruby 1.8.7.