Hello --

On Tue, 18 Dec 2001, Schlienger, Marc wrote:

> Hello,
>
> does anyone know how to create hashes at runtime?

I don't know any other way to do it in Ruby :-)

> Let's say I have an array of strings (size unknown a priori). Each of these
> strings should be a hash key. Values for the keys will also be strings but
> are not known until runtime.

There are a number of ways, depending exactly how things are stored etc.,
but probably you'd end up doing something like:

  known = %w{ eins zwei drei vier }
  unknown = %w{ one two three four }

# Pretend that unknown is unknown :-)

  h = Hash.new
  known.each_with_index { |e,i| h[e] = unknown[i] }

I don't know of any one-step way to interleaf two arrays into a hash,
although a year or so ago there was a bunch of discussion of that on
this list, and possibly some implementations floating around... i.e.,
a way to make this happen:

  h = known.hash_with(unknown)  # or something like that


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav