[#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:03806] Re: Immature idea for case-when

From: Aleksi Niemel<aleksi.niemela@...>
Date: 2000-07-04 17:39:08 UTC
List: ruby-talk #3806
> 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). 

There are two ways one can think things to happen:

  case arg
  when obj   # leading to obj.===(arg)

or

  case obj
  when arg   # leading to arg.===(obj), while we would like obj.===(arg)

Even more, we might want to have Obj.=== for common use and be able to say
"listen case, this time when comparing which 'when' might be the correct
one, do not use === please. Could you kindly check with foo?"

  case obj:method                # look, I just invented notation :)
  when arg   # leading to obj.method(arg)

This has one notable feature:

  case obj:===
  when arg

works exactly same as current version :).

	- Aleksi

In This Thread

Prev Next