Skip to content

Instantly share code, notes, and snippets.

@keithrbennett
Created October 23, 2012 23:01
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 keithrbennett/3942332 to your computer and use it in GitHub Desktop.
Save keithrbennett/3942332 to your computer and use it in GitHub Desktop.
For poster on JRuby forum to find JRuby in his Windows path
def list_candidates(extensions, command_name)
dirs = ENV['PATH'].split(File::PATH_SEPARATOR)
filespecs = []
dirs.each do |dir|
filespec_stem = File.join(dir, command_name)
extensions.each do |extension|
filespecs << (filespec_stem + extension)
end
end
filespecs
end
# filespecs = list_candidates([''], 'ruby') # for my testing on a Mac
filespecs = list_candidates(%w(.bat .exe), 'jruby')
found_filespecs, not_found_filespecs = filespecs.partition { |spec| File.exist?(spec) }
puts "\n\nNot Found:\n\n#{not_found_filespecs.join("\n")}"
puts "\n\nFound:\n\n#{found_filespecs.join("\n")}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment