require "my_utilities/version" module MyUtilities # MyUtilities class variables @help_string="" @used_single_options = [] class << self attr_accessor :help_string end def self.print_help_and_exit puts <= level super mesg end end end module MyDir def self.included base base.extend MyDirMethods end module MyDirMethods def parent_dir_match(rx, dir=".") # nil if this isn't a directory we're starting from return nil if !Dir.exists? dir return dir if !(Dir.entries(dir).select { |x| rx.match x and File.file? File.join(dir, x) }.empty?) # Don't recurse if the dir's parent is the dir return parent_dir_match(rx, File.join(dir, "..")) if(File.expand_path(dir) != '/') nil end end end private def self.generate_option_strings a=generate_single_option return [a, "#{a}_long_option"] end def self.generate_single_option # This will fail terribly after 62 incorrectly specified options ([a..z]+[A..Z]+[0..9]).each do |opt| unless @used_single_options.include? opt @used_single_options << opt return opt end end return 'a' end end class Dir include MyUtilities::MyDir end