Skip to content

Instantly share code, notes, and snippets.

@sakuro
Created May 30, 2023 04:37
Show Gist options
  • Save sakuro/5f5c5e674808ac2e50e8ae0d029d5436 to your computer and use it in GitHub Desktop.
Save sakuro/5f5c5e674808ac2e50e8ae0d029d5436 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
installed = {
mod_a: [ "1.0", "1.1", "1.2" ],
mod_b: [ "1.2" ],
}
wanted_to_use = {
mod_a: "1.1",
mod_b: "1.1",
mod_c: "1.2",
}
wanted_to_use.each do |mod, ver|
case installed.to_a
in [*, [^mod, [*, ^ver, *]], *]
puts "#{mod} is installed and version matches"
in [*, [^mod, _], *]
puts "#{mod} is installed and version does not match"
else
puts "#{mod} is not installed"
end
end
@sakuro
Copy link
Author

sakuro commented May 30, 2023

output

mod_a is installed and version matches
mod_b is installed and version does not match
mod_c is not installed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment