[#3986] Re: Principle of least effort -- another Ruby virtue. — Andrew Hunt <andy@...>

> Principle of Least Effort.

14 messages 2000/07/14

[#4043] What are you using Ruby for? — Dave Thomas <Dave@...>

16 messages 2000/07/16

[#4139] Facilitating Ruby self-propagation with the rig-it autopolymorph application. — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/07/20

[ruby-talk:03807] Re: Immature idea for case-when

From: Dave Thomas <Dave@...>
Date: 2000-07-04 20:27:18 UTC
List: ruby-talk #3807
Aleksi Niemel<aleksi.niemela@cinnober.com> writes:

> > Well, you can do something (almost) equivalent in standard Ruby--you
> > can associate closures with the 'when' conditions:
> ..
> >        when check {|n| n & 1 == 0}
> >          puts "#{number} is even"
> ..
> 
> Quite neat hack, thanks Dave! This probably solves few problems, but I could
> argue that my original case remains intact (or one have to duplicate some
> code). 

I agree it is different to the inverse case. I just thought it was fun 
to see what could be done within the current language.

>   case obj:method                # look, I just invented notation :)
>   when arg   # leading to obj.method(arg)
> 
> This has one notable feature:
> 
>   case obj:===
>   when arg

But the current method uses arg.===(obj), whereas extrapolating from
above this would be obj.===(arg)

Perhaps the way to attach this is not by extending case at all, but by 
simply defining a new selector control structure using methods in the
existing language.


Regards


Dave

In This Thread

Prev Next