[Ruby] Ruby Variable Scope[通俗易懂]

[Ruby] Ruby Variable Scope

大家好,又见面了,我是全栈君。

Scope defines where in a program a variable is accessible. Ruby has four types of variable scope, local,global, instance and class. In addition, Ruby has one constant type. Each variable type is declared by using a special character at the start of the variable name as outlined in the following table.

Name Begins With Variable Scope
$ A global variable
@ An instance variable
[a-z] or _ A local variable
[A-Z] A constant
@@ A class variable

It is useful to know, however, that a number of pre-defined global variables are available to you as a Ruby developer to obtain information about the Ruby environment. A brief summary of each of these variables is contained in the following table.

Variable Name Variable Value
$@ The location of latest error
$_ The string last read by gets
$. The line number last read by interpreter
$& The string last matched by regexp
$~ The last regexp match, as an array of subexpressions
$n The nth subexpression in the last match (same as $~[n])
$= The case-insensitivity flag
$/ The input record separator
$\ The output record separator
$0 The name of the ruby script file currently executing
$* The command line arguments used to invoke the script
$$ The Ruby interpreter’s process ID
$? The exit status of last executed child process
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/115614.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • UML——对象图「建议收藏」

    UML——对象图「建议收藏」UML——对象图

    2022年4月24日
  • c语言全局变量和局部变量问题汇总

    c语言全局变量和局部变量问题汇总

    2021年11月24日
  • 如何安装GCC

    如何安装GCC现在的CentOs8上没有自带的gcc编译器因此需要下载(注意:这里的下载是指在虚拟机中下载,不是指在电脑上下载)若运行gcc时出现appstream下载元数据失败则表明没有安装gcc。1首先需要获得root权限****在终端模式下输入su,按下回车输入密码即可(注意这里的输入密码无显示)2检查虚拟机是否联网(当然要先确保电脑已联网)3检查网络是否正常输入pingwww….

    2022年5月9日
  • visio2010密钥

    visio2010密钥GR24B-GC2XY-KRXRG-2TRJJ-4X7DCVWQ6G-37WBG-J7DJP-CY66Y-V278X2T8H8-JPW3D-CJGRK-3HTVF-VWD83HMCVF-BX8YB-JK46P-DP3KJ-9DRB222WT8-GGT7M-7MVKR-HF7Y4-MCWWDVX6BF-BHVDV-MHQ4R-KH9QD-6TQKVJ4MVP-7F4X4-V8W2C-…

    2022年5月29日
  • Utils_utility是什么意思

    Utils_utility是什么意思packagecom.example.week;importjava.io.InputStream;importjava.net.HttpURLConnection;importjava.ne

    2022年8月3日
  • JavaIO——IO概述

    JavaIO——IO概述                                                   JavaIo原理IO流用来处理设备之间的数据传输,Java程序中,对于数据的输入/输出操作都是以“流”的方式进行的。java.io包下提供了各种“流”类的接口,用以获取不同种类的数据,并…

    2022年6月3日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号