Module: WWTD::Ruby

Defined in:
lib/wwtd/ruby.rb

Class Method Summary collapse

Class Method Details

.available?(version) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/wwtd/ruby.rb', line 4

def available?(version)
  !version || switch_statement(version)
end

.switch_statement(version, options = {}) ⇒ Object

  • rvm: “rvm xxx do”

  • chruby: “chruby-exec xxx –”

  • others: env hash

  • unknown: nil



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/wwtd/ruby.rb', line 12

def switch_statement(version, options={})
  return unless version
  version = normalize_ruby_version(version)
  if rvm_executable
    command = "rvm #{version} do "
    command if cache_command("#{command} ruby -v")
  elsif chruby_executable
    command = "chruby-exec #{version} -- "
    command if cache_command("#{command} ruby -v")
  elsif options[:rerun]
    if rbenv_executable
      # cannot call different ruby from inside ruby, but ok for copy-paste
      "RBENV_VERSION=#{version} "
    else
      # don't print giant path hack :/
      "USE-RUBY-#{version}"
    end
  else
    if ruby_root = ENV["RUBY_ROOT"] # chruby or RUBY_ROOT set
      switch_via_env(File.dirname(ruby_root), version)
    elsif rbenv_executable
      rubies_root = cache_command("rbenv root") + "/versions"
      switch_via_env(rubies_root, version)
    end
  end
end