[Basic?] hash changing one key only ?

U

Une bévue

saying i do have a hash "numbers" like that :

numbers = {
"one" => 1,
"two" => 2,
"three" => 3
}

i want to translate two only into german in order to get :

numbers = {
"one" => 1,
"zwei" => 2,
"three" => 3
}

what's the best way to do that ?

does i need to do something like :

tmp_value=numbers["two"]

numbers.delete("two")

numbers["zwei"]=tmp_value

or does exist a simpler more rubyish approach ???
 
P

Premshree

Une said:
tmp_value=numbers["two"]

numbers.delete("two")

numbers["zwei"]=tmp_value

delete() returns a value object, so you don't need a temporary
variable. The following should do:

numbers["zwei"] = numbers.delete("two")

Premshree
 
U

Une bévue

Premshree said:
delete() returns a value object, so you don't need a temporary
variable. The following should do:

numbers["zwei"] = numbers.delete("two")

fantastic, much more rubyisch, thanks a lot !!!
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top