Skip to content

Instantly share code, notes, and snippets.

Created March 21, 2016 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e1f6415248453cbc82e3 to your computer and use it in GitHub Desktop.
Save anonymous/e1f6415248453cbc82e3 to your computer and use it in GitHub Desktop.
# 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