0

Hi i'am new in ruby and i want to get a Hash with string in keys and an Array in value, like this :

Hash = new HashMap
for (issue :is)
 Hash.add(is.user_name)
  if(hash.contains(is.user_name)) then
    hash.value.add(is)
   end
end

to get a result like this :

{"jane"[issue123,issue234,issue345]; "mike" [issue333,issue444,issue555]; "Alain" [issue876,issue987,issue356] }

jane have [issue123,issue234,issue345]

thanks

1 Answer 1

5

Something like below:

result = Hash.new { |hash, key| hash[key] = [] }

issues.each do |issue|
  result[issue.user_name].push issue  
end
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.