-
-
Save anonymous/e1f6415248453cbc82e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get all the unique command/argument pairs inside a hash of hashes of arrays of hashes. | |
# Example | |
extras={ | |
stage1:{ | |
job1:[ | |
{ | |
command: "cmd1", | |
argument: "arg1", | |
otherstuff: "foo" | |
}, | |
{ | |
command: "cmd1.1", | |
argument: "arg1.1", | |
otherstuff: "foo.1" | |
} | |
], | |
job2:[{ | |
command: "cmd2", | |
argument: "arg2", | |
otherstuff: "foo" | |
}] | |
}, | |
stage2:{ | |
job1:[{ | |
command: "cmd1", | |
argument: "arg1", | |
otherstuff: "foo" | |
}], | |
job2:[{ | |
command: "cmd3", | |
argument: "arg3", | |
otherstuff: "foo" | |
}] | |
} | |
} | |
# Do it | |
extras.values.map{|stage| | |
stage.values.map{|job| | |
job.map{|item| | |
{command:item[:command],argument:item[:argument]} | |
} | |
} | |
}.flatten.uniq | |
# It works, but is there a better way? | |
=> [{:command=>"cmd1", :argument=>"arg1"}, | |
{:command=>"cmd2", :argument=>"arg2"}, | |
{:command=>"cmd3", :argument=>"arg3"}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment