gpt4 book ai didi

ruby - $:<< "." do to Ruby's require path? 是什么意思

转载 作者:数据小太阳 更新时间:2023-10-29 06:47:49 24 4
gpt4 key购买 nike

我不明白$:<< "."的意思在 Ruby 中。

我将 Ruby 升级到 1.9.1,但程序无法运行。我的同学告诉我,我应该添加 $:<< "."

什么是$:<< "."做?

最佳答案

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

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

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

引用资料:

  1. 可以在 Execution Environment Variables 中找到此页面的一部分来自 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.

  2. 可以在 docs for array 中找到在 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.

关于ruby - $:<< "." do to Ruby's require path? 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8636328/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com