I access params from a controller.
I need to rename one of keys. key value to stay the same
Old name is :xx, value = 'test'
New name is :yy, value = 'test'
Simplest way to do this in one line of code?
I access params from a controller.
I need to rename one of keys. key value to stay the same
Old name is :xx, value = 'test'
New name is :yy, value = 'test'
Simplest way to do this in one line of code?
This is technically not one line but you could do.
my_var = {xx: “test”}
my_var[:yy] = my_var[:xx]; my_var.delete(:xx)
Matt
This is technically not one line but you could do.
my_var = {xx: "test"}
my_var[:yy] = my_var[:xx]; my_var.delete(:xx)
It becomes one line by:
my_var[:yy] = my_var.delete(:xx)
as Hash#delete returns the value at the specified key, or else `nil`
if there was no :xx key.