There is a hash {'results' => [], 'snow' => [], 'ham' => [], 'plow' => [] }
and I want to build a string dynamically (the keys may change), which has all the keys, excluding "results", which looks like this "snow + ham + plow"
How do i do this?
There is a hash {'results' => [], 'snow' => [], 'ham' => [], 'plow' => [] }
and I want to build a string dynamically (the keys may change), which has all the keys, excluding "results", which looks like this "snow + ham + plow"
How do i do this?
Two other ways (#1 being my preference):
h = {'results' => [], 'snow' => [], 'ham' => [], 'plow' => [] }
#1
(h.keys - ['results']).join(' + ') #=> "snow + ham + plow"
#2
a = h.keys
a.delete('results')
a.join(' + ') #=> "snow + ham + plow"
Array#delete and Array.join both have to iterate behind the scenes.keys as well.) Edited. Readers: formerly I said "Without iterating:".