hash key to var name of value hash key value

Discussion in 'Ruby' started by Une bévue, Aug 10, 2006.

  1. Une bévue

    Une bévue Guest

    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, Aug 10, 2006
    #1
    1. Advertising

  2. Une bévue

    Alex Young Guest

    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
     
    Alex Young, Aug 10, 2006
    #2
    1. Advertising

  3. On 8/10/06, Alex Young <> wrote:
    >
    > hash.each_key{|k|
    > eval("#{k}=hash[#{k}]")
    > }


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

    martin
     
    Martin DeMello, Aug 10, 2006
    #3
  4. Une bévue

    Une bévue Guest

    Martin DeMello <> wrote:

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


    fine thanxs to both of them !!!
    --
    une bévue
     
    Une bévue, Aug 10, 2006
    #4
  5. Une bévue

    Guest

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

    >
    > 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
     
    , Aug 10, 2006
    #5
  6. Une bévue

    Une bévue Guest

    <> wrote:

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


    ok fine, may it's the best ?
    --
    une bévue
     
    Une bévue, Aug 10, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alvin Bruney

    Threads.. Session var lost, App var ok

    Alvin Bruney, Dec 2, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    378
    rooster575
    Dec 2, 2003
  2. thomson
    Replies:
    10
    Views:
    2,521
    Eliyahu Goldin
    Jun 20, 2005
  3. thomson
    Replies:
    0
    Views:
    401
    thomson
    Jun 20, 2005
  4. Fred
    Replies:
    3
    Views:
    336
    Alf P. Steinbach
    Aug 10, 2003
  5. Antonio Quinonez
    Replies:
    2
    Views:
    184
    Antonio Quinonez
    Aug 14, 2003
Loading...

Share This Page