$:<<是什么? “." Ruby的require路径? [英] What does $:<< "." do to Ruby's require path?

查看:78
本文介绍了$:<<是什么? “." Ruby的require路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不理解Ruby中$:<< "."的含义.

I don't understand the meaning of $:<< "." in Ruby.

我将Ruby升级到1.9.1,但是某个程序无法正常工作.我的同学告诉我应该加$:<< "."

I upgraded Ruby to 1.9.1, but a program was not working. My classmate told me that I am supposed to add $:<< "."

$:<< "."的作用是什么?

推荐答案

  1. $:是包含构成Ruby加载路径的路径数组的变量
  2. <<将一个项目附加到数组的末尾
  3. .引用当前目录

  1. $: is the variable that holds an array of paths that make up your Ruby's load path
  2. << appends an item to the end of the array
  3. . refers to the current directory

1   2  3
|   |  |
V   V  V
$: << "."

因此,您要将当前目录添加到Ruby的加载路径

So you are adding the current directory to Ruby's load path

参考:

  1. 可以在此页面的Execution Environment Variables部分中找到,网址为《实用程序员指南》

  1. Can be found in the Execution Environment Variables section of of this page from The Pragmatic Programmers Guide

字符串数组,其中每个字符串指定要搜索的目录,以查找load和require方法使用的Ruby脚本和二进制扩展名.初始值是通过-I命令行选项传递的参数的值,后跟安装定义的标准库位置,后跟当前目录(.").[显然,此链接适用于旧版本的Ruby.因为它仍然在那里].可以在程序中设置此变量以更改默认搜索路径;通常,程序使用$:<< dir以将dir附加到路径.

An array of strings, where each string specifies a directory to be searched for Ruby scripts and binary extensions used by the load and require methods. The initial value is the value of the arguments passed via the -I command-line option, followed by an installation-defined standard library location, followed by the current directory (".")[Obviously this link is for an older version of Ruby as this is still in there]. This variable may be set from within a program to alter the default search path; typically, programs use $: << dir to append dir to the path.

  • 可以在文档中找到数组在ruby-doc.org.

  • Can be found in the docs for array at ruby-doc.org.

    附加-将给定对象推到此数组的末尾.该表达式返回数组本身,因此可以将多个追加链接在一起.

    Append—Pushes the given object on to the end of this array. This expression returns the array itself, so several appends may be chained together.

  • 这篇关于$:&lt;&lt;是什么? “." Ruby的require路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆