Sunday, 29 September 2013

split a symbol hash into string arrays of keys and values

split a symbol hash into string arrays of keys and values

Is there any way to split a symbol hash into string arrays of keys and
values ?
for example:
array = [:key1 => val1,:key2 => val2]
Should be:
keys = ['key1', 'key2']
values = ['val1','val2']
I know I can do it by this way:
keys = array.keys.map { |key| key.to_s }
values = array.values.map { |key| key.to_s }
But I would like to do it in just one command.

No comments:

Post a Comment