I have the following Ruby code:
我有以下Ruby代码:
settings= hash.new
settings= batch.getPartialSettings
settings= batchSettings.merge(batch.getEntireSettings)
puts settings
The result is:
结果是:
{"Resolution"=>"1024", "Applications"=>"Mozilla,IE,Chrome", "Programming"=>"Java,HTML"}
I want "Applications"
to be sorted as:
我希望“应用程序”排序为:
"Applications"=>"Chrome,IE,Mozilla"
So, my final result should be:
所以,我的最终结果应该是:
{"Resolution"=>"1024", "Applications"=>"Chrome,IE,Mozilla", "Programming"=>"Java,HTML"}
1 个解决方案
#1
3
unsorted_apps = settings['Applications']
sorted_apps = unsorted_apps.split(',').sort.join(',')
settings['Applications'] = sorted_apps
#1
3
unsorted_apps = settings['Applications']
sorted_apps = unsorted_apps.split(',').sort.join(',')
settings['Applications'] = sorted_apps