hash key to var name of value hash key value

U

Une bévue

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 ))))
 
A

Alex Young

Une said:
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...
 
A

ara.t.howard

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

IN_NEWS=3D@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 ))))


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

-a
--=20
to foster inner awareness, introspection, and reasoning is more efficient t=
han
meditation and prayer.
- h.h. the 14th dali lama
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,687
Latest member
IngridXxj

Latest Threads

Top