Sha256: 87dd42b6d198953e26071dd0dfd94f0edc6446312d2a44c7217266614a9aba66
Contents?: true
Size: 1.4 KB
Versions: 3
Compression:
Stored size: 1.4 KB
Contents
module Aai module Utils # Raises SystemExit if one of the fnames does not exist. def check_files fnames fnames.each do |fname| AbortIf.abort_unless_file_exists fname end end def two_ary_permutations a1, a2 permutations = [] a1.each do |elem1| a2.each do |elem2| permutations << [elem1, elem2] << [elem2, elem1] end end permutations end def one_way_combinations a1, a2, no_duplicates=true permutations = [] a1.each do |elem1| a2.each do |elem2| if !no_duplicates || (no_duplicates && elem1 != elem2) permutations << [elem1, elem2] end end end permutations end # from https://stackoverflow.com/questions/2108727/ \ # which-in-ruby-checking-if-program-exists-in-path-from-ruby def command? cmd exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) end end return nil end def check_command cmd path = command? cmd AbortIf.abort_unless path, "Missing #{cmd} command. " + "Is it executable and on your path?" path end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
aai-0.3.0 | lib/aai/utils.rb |
aai-0.2.2 | lib/aai/utils.rb |
aai-0.2.1 | lib/aai/utils.rb |