我有一个类将检查用户环境以了解他们是否已python
安装,这些类的目的是检查用户是否安装了多个版本的 python 并且不默认为三个:
class CheckForPythonicVariables
class << self
def find_python_env_var
py_path = [] # Results of the python env variables
env_vars = ENV.to_h
items = env_vars["Path"].split(";") # Split the environment variables into an array
items.each { |var|
if var.to_s.include?("Python") # Do you have python?
py_path.push(var)
end
}
py_path.each { |python|
if python.include?("Python27") # Python 2.7.x?
return true
elsif python.include?("Python3") # Python 3.x.x?
return false
else
raise "You do not have python installed"
end
}
end
end
end
现在这有效,但它只适用于 Windows 和少数 Linux OS
,显然Parrot
不是其中之一。有没有办法#split()
通过任何不是字母的东西来设置环境变量?例如:
Windows 环境变量:C:\Python27\;C:\Python27\Scripts;C:\ProgramData\Oracle\Java\javapath
Parrot OS 环境变量:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
请注意变量是如何被分号(;
)或冒号(:
)分割的,有没有一种方法可以在 ruby 中使用该#split()
函数并被任何非字母数字字符或数字分割?或者有没有更好的方法来确保用户python 2.7.x
在他们的环境变量中有?