ruby - how do i get the uniq value for this hash? -


i want uniq region , filtered "status = stopped". without using loop. possible?

hash:

{"a123" => {"status"=>"stopped", "region"=>"us-east"},  "b123" => {"status"=>"stopped", "region"=>"us-east"},  "c123" => {"status"=>"stopped", "region"=>"us-west"},  "d123" => {"status"=>"running", "region"=>"us-west"},  "e123" => {"status"=>"running", "region"=>"us-north"}} 

my code filtering status:

hash.select{ |k, v| v["status"] == "stopped" }.values  #=> [{"status"=>"stopped", "region"=>"us-east"},      {"status"=>"stopped", "region"=>"us-east"},      {"status"=>"stopped", "region"=>"us-west"}] 

i dont know what's next , want output :

#=> {"us-east", "us-west"} 

i'm noob in ruby , hash. please ^_^

hash.map {|_,v| v['region'] if v['status'] == 'stopped'}.compact.uniq # => ["us-east", "us-west"] 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -