0

I have the following Ruby code:

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"}
6
  • Welcome to Stack Overflow. It's not necessary to add salutations ("hi!"), valedictions ("thanks a lot") or signatures to questions because Stack Overflow isn't a bulletin board. It's a question and answer reference site; Think of it like a cook book or an encyclopedia. People ask questions and others supply answers on how to do it. We don't care if you're new to a language or have worked with it for years, a well-asked question is what is important. Commented Jun 30, 2014 at 19:19
  • @theTinMan You frequently seem to edit and add question marks to titles where putting one is grammatically wrong. What is that? If you edit, you should be careful not to make it wrong. Commented Jun 30, 2014 at 19:26
  • Questions end with question marks. It's acceptable to write a terse question, but, even so, they always end with question marks. Commented Jun 30, 2014 at 19:28
  • @theTinMan In this case, the title is not a question. It is a phrase. Commented Jun 30, 2014 at 20:06
  • @UliAgassi If you intended to make sense of the question mark, "How to ..." is a (nominal) phrase, is it not a question, and the question mark is still inappropriate. If you change it to "How can I ...", then it is a question, and the question mark becomes appropriate. Commented Jun 30, 2014 at 20:09

1 Answer 1

3
unsorted_apps = settings['Applications']
sorted_apps = unsorted_apps.split(',').sort.join(',')
settings['Applications'] = sorted_apps
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.