博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ruby 预定义 常量 & 变量
阅读量:6504 次
发布时间:2019-06-24

本文共 4746 字,大约阅读时间需要 15 分钟。

hot3.png

Ruby Predefined Variables

Variable Name Description
$! The last exception object raised. The exception object can also be accessed using => in rescue clause.
$@ The stack backtrace for the last exception raised. The stack backtrace information can retrieved by Exception#backtrace method of the last exception.
$/ The input record separator (newline by default). gets, readline, etc., take their input record separator as optional argument.
$\ The output record separator (nil by default).
$, The output separator between the arguments to print and Array#join (nil by default). You can specify separator explicitly to Array#join.
$; The default separator for split (nil by default). You can specify separator explicitly for String#split.
$. The number of the last line read from the current input file. Equivalent to ARGF.lineno.
$< Synonym for ARGF.
$> Synonym for $defout.
$0 The name of the current Ruby program being executed.
$$ The process pid of the current Ruby program being executed.
$? The exit status of the last process terminated.
$: Synonym for $LOAD_PATH.
$DEBUG True if the -d or --debug command-line option is specified.
$defout The destination output for print and printf ($stdout by default).
$F The variable that receives the output from split when -a is specified. This variable is set if the -a command-line option is specified along with the -p or -n option.
$FILENAME The name of the file currently being read from ARGF. Equivalent to ARGF.filename.
$LOAD_PATH An array holding the directories to be searched when loading files with the load and require methods.
$SAFE The security level
  • 0 --> No checks are performed on externally supplied (tainted) data. (default)

  • 1 --> Potentially dangerous operations using tainted data are forbidden.

  • 2 --> Potentially dangerous operations on processes and files are forbidden.

  • 3 --> All newly created objects are considered tainted.

  • 4 --> Modification of global data is forbidden.

$stdin Standard input (STDIN by default).
$stdout Standard output (STDOUT by default).
$stderr Standard error (STDERR by default).
$VERBOSE True if the -v, -w, or --verbose command-line option is specified.
$- x The value of interpreter option -x (x=0, a, d, F, i, K, l, p, v). These options are listed below
$-0 The value of interpreter option -x and alias of $/.
$-a The value of interpreter option -x and true if option -a is set. Read-only.
$-d The value of interpreter option -x and alias of $DEBUG
$-F The value of interpreter option -x and alias of $;.
$-i The value of interpreter option -x and in in-place-edit mode, holds the extension, otherwise nil. Can enable or disable in-place-edit mode.
$-I The value of interpreter option -x and alias of $:.
$-l The value of interpreter option -x and true if option -lis set. Read-only.
$-p The value of interpreter option -x and true if option -pis set. Read-only.
$_ The local variable, last string read by gets or readline in the current scope.
$~ The local variable, MatchData relating to the last match. Regex#match method returns the last match information.
$ n ($1, $2, $3...) The string matched in the nth group of the last pattern match. Equivalent to m[n], where m is a MatchData object.
$& The string matched in the last pattern match. Equivalent to m[0], where m is a MatchData object.
$` The string preceding the match in the last pattern match. Equivalent to m.pre_match, where m is a MatchData object.
$' The string following the match in the last pattern match. Equivalent to m.post_match, where m is a MatchData object.
$+ The string corresponding to the last successfully matched group in the last pattern match.

Ruby Predefined Constants

Constant Name Description
TRUE Synonym for true.
FALSE Synonym for false.
NIL Synonym for nil.
ARGF An object providing access to virtual concatenation of files passed as command-line arguments or standard input if there are no command-line arguments. A synonym for $<.
ARGV An array containing the command-line arguments passed to the program. A synonym for $*.
DATA An input stream for reading the lines of code following the __END__ directive. Not defined if __END__ isn't present in code.
ENV A hash-like object containing the program's environment variables. ENV can be handled as a hash.
RUBY_PLATFORM A string indicating the platform of the Ruby interpreter.
RUBY_RELEASE_DATE A string indicating the release date of the Ruby interpreter
RUBY_VERSION A string indicating the version of the Ruby interpreter.
STDERR Standard error output stream. Default value of $stderr.
STDIN Standard input stream. Default value of $stdin.
STDOUT Standard output stream. Default value of $stdout.
TOPLEVEL_BINDING A binding object at Ruby's top level.

转载于:https://my.oschina.net/xieyunzi/blog/292255

你可能感兴趣的文章
hikariconfig mysql_HikariConfig配置解析
查看>>
mysql批量数据多次查询数据库_mysql数据库批量操作
查看>>
jquery 乱码 传参_jquery获取URL中参数解决中文乱码问题的两种方法
查看>>
JDBC_MySQL_jdbc连接mysql_MySQL
查看>>
mysql cte的好处_Mysql 8 重要新特性 - CTE 通用表表达式
查看>>
zcu106 固化_xilinx zcu106 vcu demo
查看>>
java ftpclient 代码_java后台代码ftpclient下载文件
查看>>
java数据库生成model_继承BaseModelGenerator 生成Model时添加数据库表字段 生成代码示例...
查看>>
java面向对象的概念_java面向对象(上)-- 面向对象的概念
查看>>
java内部类访问外部类变量 final_Java内部类引用外部类中的局部变量为什么必须是final问题解析...
查看>>
java 栈帧与类的关系_深入理解Java虚拟机之类运行时栈帧结构
查看>>
php中删除评论怎么做的,详解PHP如何实现评论回复删除功能
查看>>
macports 安装php,「macports」MacOS 中 MacPorts 安装和使用 - 金橙教程网
查看>>
php 审计 for linux,for linux是什么意思
查看>>
matlab里面连接器是什么,Oops - an error has occurred
查看>>
matlab建立桌面图标,在ubuntu16.04上创建matlab的快捷方式(实现方法)
查看>>
smarty使用php代码,笑谈配置,使用Smarty技术_php
查看>>
oracle数据实际值限制,c# – Oracle数据库TNS密钥“数据源”的值长度超过了’128’的限制...
查看>>
silk v3 decoder php,解码转换QQ微信的SILK v3编码音频为MP3或其他格式
查看>>
linux不能访问80端口,lunux开放80端口(本地访问不了linux文件可能是这个原因)...
查看>>