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

前端之家收集整理的这篇文章主要介绍了什么是$:<<“.”做Ruby的需求路径?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我不明白$的含义:<< “”在 Ruby中.

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

解决方法

> $:是包含构成Ruby加载路径的路径数组的变量
><<将一个项目附加到数组的末尾
>.指当前目录 @H_403_10@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.

原文链接:https://www.f2er.com/ruby/266992.html

猜你在找的Ruby相关文章