加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

什么是$:<<“.”做Ruby的需求路径?

发布时间:2020-12-16 21:44:20 所属栏目:百科 来源:网络整理
导读:我不明白$的含义: “”在 Ruby中. 我将Ruby升级到1.9.1,但程序不起作用.我的同学告诉我,我应该添加$: “” 什么是$: “”做? 解决方法 $:是包含构成Ruby加载路径的路径数组的变量 将一个项目附加到数组的末尾 .指当前目录 1 2 3| | |V V V$: "." 所以你
我不明白$的含义:<< “”在 Ruby中.

我将Ruby升级到1.9.1,但程序不起作用.我的同学告诉我,我应该添加$:<< “” 什么是$:<< “”做?

解决方法

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

所以你将当前目录添加到Ruby的加载路径

参考文献:

>可从The Pragmatic Programmers Guide的此页面的“执行环境变量”部分找到

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的docs for array中找到.

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读