“$"是什么意思?Ruby 中的字符是什么意思? [英] What does the "$" character mean in Ruby?
问题描述
使用 Ruby on Rails 一段时间后决定查看实际源代码.从 GitHub 上获取 repo 并开始环顾四周.遇到一些我不确定它做什么或引用什么的代码.
Been playing with Ruby on Rails for awhile and decided to take a look through the actual source. Grabbed the repo from GitHub and started looking around. Came across some code that I am not sure what it does or what it references.
我在 actionmailer/test/abstract_unit.rb 中看到了这段代码
I saw this code in actionmailer/test/abstract_unit.rb
root = File.expand_path('../../..', __FILE__)
begin
require "#{root}/vendor/gems/environment"
rescue LoadError
$:.unshift("#{root}/activesupport/lib")
$:.unshift("#{root}/actionpack/lib")
end
lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
require 'rubygems'
require 'test/unit'
require 'action_mailer'
require 'action_mailer/test_case'
谁能告诉我 $:(又名金光闪闪")指的是什么?
Can someone tell me what the $: (a.k.a. "the bling") is referencing?
推荐答案
$:是用于查找外部文件的全局变量.
$: is the global variable used for looking up external files.
来自 http://www.zenspider.com/Languages/Ruby/QuickRef.html#18
$:通过 load 或 require 加载脚本和二进制模块的路径.
$: Load path for scripts and binary modules by load or require.
这篇关于“$"是什么意思?Ruby 中的字符是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!