Skip to content

Instantly share code, notes, and snippets.

@unak
Last active December 15, 2017 09:06
Show Gist options
  • Save unak/6b5838644fa629c5a58212097c274a19 to your computer and use it in GitHub Desktop.
Save unak/6b5838644fa629c5a58212097c274a19 to your computer and use it in GitHub Desktop.
allruby script for Windows
@echo off
C:\opt\ruby\bin\ruby.exe -x %~f0 %*
goto :EOF
#!ruby
require "yaml"
cache = File.join(File.dirname(__FILE__), "allruby.cache")
if File.exist?(cache)
rubies = YAML.load(File.read(cache))
else
rubies = {}
end
changed = false
Dir.glob("C:/opt/*/bin/ruby.exe").each do |ruby|
unless rubies.include?(ruby)
rubies[ruby] = `#{ruby} -v`.chomp.chomp
changed = true
end
end
File.write(cache, rubies.to_yaml) if changed
rubies.sort_by{|_, v| v}.each do |ruby, _|
puts rubies[ruby]
system(ruby, *ARGV)
end
@unak
Copy link
Author

unak commented Dec 15, 2017

expects that all rubies are installed in C:/opt/* directory (like C:/opt/ruby-2.4.3), and there is "base ruby" in C:/opt/ruby.
Change line 2 and 14 for your environment.

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