[#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:04256] Re: TABWTDI and Hash.new([])

From: matz@... (Yukihiro Matsumoto)
Date: 2000-07-28 16:15:48 UTC
List: ruby-talk #4256
Hi,

In message "[ruby-talk:04251] Re: TABWTDI and Hash.new([])"
    on 00/07/28, Dave Thomas <Dave@thomases.com> writes:

|In these circumstances, Hugh would like a new default value to be
|created. So, Matz, how about the following:
|
|1. Hash.new takes a second parameter:
|
|    Hash.new(default,  genNewDefaults=false)
|
|2. Whenever you currently return hash->ifnone, instead have
|
|      default = hash->ifnone
|
|      return default unless genNewDefaults
|
|      if default.kind_of? Class
|           return default.new
|      else
|           return default.dup
|      end

I'm thinking of another way:

     Hash.new{[]}

This means if the key is not found in the hash, evaluate given block
and returns its value as default.  In this example, the block creates
new array for each execution.

							matz.

In This Thread