Let's guess I have a hash like this:
my_hash={
loginame: :"pepe",
name: :"Duuuo",
zip: {default: '00000', correct: :'54666'},
city: {
uno: "1",
dentro: {
default: "Madrid",
original: "Barcelona"
}
},
accent: [
10,
20,
{
original: "spanish",
learned: "german"
}
]
}
And we have an array of unknown paths to the values in the hash, for example: keys=[
"[:city][:dentro][:original]",
"[:accent][1]",
"[:accent][2][:original]"
]
And I want to know the value in the hash on that path, for that purpose I am using in my code 'eval'
keys.each{|key|
puts eval "my_hash#{key}"
}
But apart of not being elegant... there are many risks, so I would like to know if you propose any other better way
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 147:13:19 |
Calls: | 10,383 |
Calls today: | 8 |
Files: | 14,054 |
D/L today: |
2 files (1,861K bytes) |
Messages: | 6,417,728 |