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

From: Aleksi Niemel<aleksi.niemela@...>
Date: 2000-07-04 16:34:14 UTC
List: ruby-talk #3801
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

This is actually quite ugly, but the point is clear. The better structure
could be:

  case obj method_it_has
  when arguments_to, be_passed
  when args2
  end

Effectively same as:

  if obj.method_it_has(arguments_to, be_passed)
  elsif obj.method_it_has(args2)
  end

Applied for same example:

  case obj.ancestors include?  # now, how to make function references?
  when Foo
    puts "Hey we have a Foo descendant here."
  when Bar
    puts "Blaahr."
  end

There might be some other interesting variations. Just to make it clear: I'm
not saying this is good feature to have nor promoting this! This might be
good, might need amount of tinkering before it's "right" or might be
outright simple, plain wrong.

Think about it, and tell me. (Or tell matz :).

	- Aleksi

In This Thread

Prev Next