什么是“$:”?在红宝石? [英] what is "$:" in ruby?

查看:109
本文介绍了什么是“$:”?在红宝石?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常可以在.gemspec文件中看到。例如。 i18n.gemspec

  $:<< File.expand_path('../ lib',__FILE__)


解决方案

 预先定义的变量
$!由'raise'设置的异常信息消息。
$ @抛出最后一个异常的回溯数组。
$&最后一次成功匹配的字符串。
$`最后一次成功匹配左侧的字符串。
$'上一次成功匹配右侧的字符串。
$ +最后一场成功比赛的最高分组。
$ 1上次成功比赛的第N组。可能> 1.
$〜关于当前范围中上次匹配的信息。
$ =不区分大小写的标志,默认为零。
$ /输入记录分隔符,默认为换行符。
$ \打印和IO#写入的输出记录分隔符。缺省值为零。
$,打印和Array#连接的输出字段分隔符。
$; String#split的默认分隔符。
$。读取的最后一个文件的当前输入行号。
$<在命令行上给出的文件的虚拟连接文件(如果没有给出文件,则从$ stdin中获得)。
$> printf的默认输出printf。 $ stdout默认。
$ _通过gets或readline获取字符串的最后一个输入行。
$ 0包含正在执行的脚本的名称。可以分配。
$ *为脚本提供的命令行参数sans args。
$$运行此脚本的Ruby的进程号。
$?最后执行的子进程的状态。
$:按加载或需求加载脚本和二进制模块的路径。
$该数组包含由require加载的模块名称
$ DEBUG -d开关的状态
$ FILENAME当前输入文件从$< ;.与$< ;.相同。 filename
$ LOAD_PATH $:
$ stderr的别名当前标准错误输出
$ stdin当前标准输入
$ stdout当前标准输出
$ VERBOSE详细标志,由-v开关设置
$ -0别名为$ /。
$ -a如果设置了选项-a,则为真只读变量。
$ -d别名为$ DEBUG。
$ -F别名为$ ;.
$ -i在就地编辑模式下,该变量保存扩展名,否则为零。
$ -I别名为$ :.
$ -l设置选项-l时为真只读变量
$ -p设置选项-p时为真Read
$ -v别名为$ VERBOSE
$ -w如果设置了-w选项,则为真

上述捷径是一个不幸的Pe过时!有些英文名称可用于其中一些,这些都是不言而喻的,应该在可用的情况下使用。

另请参阅: http://ruby.runpaint.org/globals



另请参阅: http://www.zenspider.com/Languages/Ruby/QuickRef.html

Usually be seen in .gemspec file. eg. i18n.gemspec.

$: << File.expand_path('../lib', __FILE__)

解决方案

Pre-defined variables
$!         The exception information message set by 'raise'.
$@         Array of backtrace of the last exception thrown.
$&         The string matched by the last successful match.
$`         The string to the left  of the last successful match.
$'         The string to the right of the last successful match.
$+         The highest group matched by the last successful match.
$1         The Nth group of the last successful match. May be > 1.
$~         The information about the last match in the current scope.
$=         The flag for case insensitive, nil by default.
$/         The input record separator, newline by default.
$\         The output record separator for the print and IO#write. Default is nil.
$,         The output field separator for the print and Array#join.
$;         The default separator for String#split.
$.         The current input line number of the last file that was read.
$<         The virtual concatenation file of the files given on command line (or from $stdin if no files were given).
$>         The default output for print, printf. $stdout by default.
$_         The last input line of string by gets or readline.
$0         Contains the name of the script being executed. May be assignable.
$*         Command line arguments given for the script sans args.
$$         The process number of the Ruby running this script.
$?         The status of the last executed child process.
$:         Load path for scripts and binary modules by load or require.
$"         The array contains the module names loaded by require.
$DEBUG     The status of the -d switch.
$FILENAME  Current input file from $<. Same as $<.filename.
$LOAD_PATH The alias to the $:.
$stderr    The current standard error output.
$stdin     The current standard input.
$stdout    The current standard output.
$VERBOSE   The verbose flag, which is set by the -v switch.
$-0        The alias to $/.
$-a        True if option -a is set. Read-only variable.
$-d        The alias to $DEBUG.
$-F        The alias to $;.
$-i        In in-place-edit mode, this variable holds the extension, otherwise nil.
$-I        The alias to $:.
$-l        True if option -l is set. Read-only variable.
$-p        True if option -p is set. Read-only variable.
$-v        The alias to $VERBOSE.
$    -w        True if option -w is set.

the above shortcuts are an unfortunate Perl anachronism! There are "English Names" available for some of them, which are self-explanatory, and which should be used if available.

see also: http://ruby.runpaint.org/globals

see also: http://www.zenspider.com/Languages/Ruby/QuickRef.html

这篇关于什么是“$:”?在红宝石?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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