From: Park Heesob Date: 2002-06-05T14:00:31+09:00 Subject: Re: Dynamic local variables ? "Han Holl" wrote in message news:3CFD3100.3010404@pobox.com... > > Is it possible at all to generate local variables dynamically ? > What I need is roughly this: > I read in a file with one or more multidimensional hashes: > > table = Tabel.new("/tmp/rubdefs.text") > puts table["rub"]["T"]["datumontvangst"] > > I want to access this as: > rub["T"]["datumontvangst"] > Hi, I think PHP's extract and compact function is useful. extract -- Import variables into the current symbol table from an array compact -- Create array containing variables and their values I implemented with ruby using global variable. def extract(hash) hash.each do |key,value| eval "$#{key} = #{value.inspect}" end end def compact(*arg) hash = {} arg.each do |key| hash[key] = eval "$#{key}" end hash end var_hash = {"color" => "blue", "size" => "medium", "shape" => "sphere"} extract(var_hash) puts $color, $size, $shape,"\n" var_hash2 = compact('color','size','shape') Park Heesob.