On Jan 22, 2006, at 19:14, John Carter wrote:

> Trick Two...
>
> Memoization
>
> class Foo
>   def initialize( thing)
>   end
> end
>
> foo = Foo.new( thing)
>
> becomes...
>
> class Foo
>   @@memo = Hash.new{|hash,key| hash[key] = Foo.new( key)}
>
>   def create_foo( thing)
>    @@memo[thing]
>   end
>
>   def initialize( thing)
>   end
>
> end
>
>
> foo = Foo.create_foo( thing)

Er, um, huh?

All foo-links are tapping into a global-to-class hash called @@memo. 
OK...
Foo.new has been rendered useless, apparently torturing anybody who 
forgets by returning nil as a non-error?
Foo.create_foo(thing) does, well, I have no idea. What's "thing" 
supposed to be? And why is create_foo using square brackets?

Sigh. Sometimes Ruby is *too* idiomatic.

What *is* "memo-ization?"