Ruby에 대한 지식이 거의 없지만 내 사무실에 대한 Vagrant VM을 연구 중이다. 변수를 설정하여 각 개발자가 쉽게 사용자 정의 할 수 있도록 설정했지만 외부 파일의 변수를 포함하려고 할 때 문제가 발생합니다.Strange Ruby scoping issue (내 생각 엔)
# Local (host) system info
host_os = "Windows"
nfs_enabled = false
# IP and Port Configuration
vm_ip_address = "33.33.33.10"
vm_http_port = 80
host_http_port = 8888
vm_mysql_port = 3306
host_mysql_port = 3306 # Warning, mysql port configuration using 3306 will interfere with any locally run MySQL server.
local_sites_path = "D:\\Web"
vm_sites_path = ENV["HOME"] + "/Sites"
# VM Configuration
vm_memory = "1024"
Vagrant.configure("2") do |config|
... do vagrant stuff here
그러나,이 작동하지 않습니다 (config.local.rb의 내용이 위의 변수 선언과 일치) :
여기 (이 작품) 내가 뭐하는 거지의 기본 취지이다if(File.file?("config.local.rb"))
require_relative 'config.local.rb'
else
# Local (host) system info
host_os = "Mac"
nfs_enabled = true
# IP and Port Configuration
vm_ip_address = "33.33.33.10"
vm_http_port = 80
host_http_port = 8888
vm_mysql_port = 3306
host_mysql_port = 3306 # Warning, mysql port configuration using 3306 will interfere with any locally run MySQL server.
local_sites_path = ENV["HOME"] + "/Sites"
vm_sites_path = ENV["HOME"] + "/Sites"
# VM Configuration
vm_memory = "512"
end
Vagrant.configure("2") do |config|
... do vagrant stuff here
아이디어가 있습니까? 두 경우 모두 변수 선언은 파일의 맨 위에 있으므로 내 이해는 전역 범위에 있어야한다는 것입니다. 여기
는 config.local.rb의 내용입니다 : 내가 말했듯이, 난 정말 전에 루비를 사용하지 않은# Duplicate to config.local.rb to activate. Override the variables set in the Vagrantfile to tweak your local VM.
# Local (host) system info
host_os = "Windows"
nfs_enabled = false
# IP and Port Configuration
vm_ip_address = "33.33.33.10"
vm_http_port = 80
host_http_port = 8888
vm_mysql_port = 3306
host_mysql_port = 3306 # Warning, mysql port configuration using 3306 will interfere with any locally run MySQL server.
local_sites_path = "D:\\Web"
vm_sites_path = ENV["HOME"] + "/Sites"
# VM Configuration
vm_memory = "1024"
,하지만 난 프로그래밍 및 범위에 대해 알고있는 모든이가 잘 작동해야한다고 말한다 . (print
문장을 사용하여) 파일이 스크립트에 의해 감지되고 포함되어 있는지 확인했지만 Vagrantfile에 직접 설정을 하드 코딩하지 않으면 어떤 이유로 작동하지 않습니다.
미리 감사드립니다.
매우 지연 응답하지만,이 문제였다
더 나은, 필요에 따라 할 수 있습니다 당신은 아마 대신 루비 파일의 YAML 파일에서 구성 데이터를 입력해야처럼 그 접근 방식이 보인다면
. 나는 루비의 전역 변수가'$'를 필요로한다는 것을 몰랐다. – ChimericDream