Hash key to var name of value hash key value

i'd like to now if their is a simpler way to do that :

IN_NEWS=@h['IN_NEWS']

because here i do have to know their is a key of name "IN_NEWS"

want i want is to affet the value of all the @h['key_name'] to the
variable key_name ???

(as far as i remember well it's possible in php then i think this is
also possible in ruby ))))

···

--
une bévue

Une bévue wrote:

i'd like to now if their is a simpler way to do that :

IN_NEWS=@h['IN_NEWS']

because here i do have to know their is a key of name "IN_NEWS"

want i want is to affet the value of all the @h['key_name'] to the
variable key_name ???

(as far as i remember well it's possible in php then i think this is
also possible in ruby ))))

Thinking out loud...

hash.each_key{|k|
   eval("#{k}=hash[#{k}]")
}

There may be a better way, though...

···

--
Alex

define_method('key_name'){ @h['key_name' }

-a

···

On Thu, 10 Aug 2006, [ISO-8859-1] Une bévue wrote:

i'd like to now if their is a simpler way to do that :

IN_NEWS=@h['IN_NEWS']

because here i do have to know their is a key of name "IN_NEWS"

want i want is to affet the value of all the @h['key_name'] to the
variable key_name ???

(as far as i remember well it's possible in php then i think this is
also possible in ruby ))))

--
to foster inner awareness, introspection, and reasoning is more efficient than
meditation and prayer.
- h.h. the 14th dali lama

hash.each_pair {|k,v|
  Object.const_set(k, v)
}

martin

···

On 8/10/06, Alex Young <alex@blackkettle.org> wrote:

hash.each_key{|k|
   eval("#{k}=hash[#{k}]")
}

ok fine, may it's the best ?

···

<ara.t.howard@noaa.gov> wrote:

define_method('key_name'){ @h['key_name' }

--
une bévue

fine thanxs to both of them !!!

···

Martin DeMello <martindemello@gmail.com> wrote:

hash.each_pair {|k,v|
  Object.const_set(k, v)
}

--
une bévue