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) ⇒ Object

  • rvm: “rvm xxx do”

  • others: env hash

  • unknown: nil



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wwtd/ruby.rb', line 11

def switch_statement(version)
  return unless version
  version = normalize_ruby_version(version)
  if rvm_executable
    command = "rvm #{version} do "
    command if cache_command("#{command} ruby -v")
  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