[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,globalinstance 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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 16天记住7000考研单词

    16天记住7000考研单词16天记住7000考研单词(第一天)1.WithmyownearsIclearlyheardtheheartbeatofthenuclearbomb.我亲耳清楚地听到原子弹的心脏的跳动。2.Nextyearthebeardedbearwillbearadearbabyintherear.明年,长胡子的熊将在后方产一头可爱的小崽.

    2022年5月29日
    35
  • CSS calc()函数与单位vh 常见height:100vh[通俗易懂]

    CSS calc()函数与单位vh 常见height:100vh[通俗易懂]calc()函数属于CSS3版本内容,用于动态计算长度值。例如:width:calc(100%-10px);需要注意的是,运算符前后都需要保留一个空格。calc()函数支持”+”,”-“,”*”,”/”运算;举例,给一个div动态设置宽度如下:#divBox{position:absolute;left:50px;width:calc(100%-100p…

    2022年6月5日
    49
  • iPhone使用教程_iphone基础使用

    iPhone使用教程_iphone基础使用iPhone史上最全的使用教程iPhone的解锁、越狱、激活、固件等等是什么意思,有什么分别这几天看见好多新人问这几个词的含义及区别。我在这儿说说我的看法,不是官方解释,不懂的学习一下,懂的绕道,如有错误,敬请指正!第一次买来时或恢复官方固件后,iPhone会处于那种只能拨打紧急电话状态,不能使用其它功能,如果要使用其它功能,就必须进行一项操作,那就是“激活”。一般有锁版的只有使…

    2025年11月23日
    5
  • MongoDB 配置

    MongoDB 配置

    2022年3月12日
    47
  • ajax的responseText是什么东西

    你向ajax后台的程序发送xmlhttp请求的时候,后台程序接到请求会进行处理,处理结束后,可以返回一串数据给前台,这个就是responseText. 一般在后台程序C#中是Response.Write(“字符串”)php中使用的是echo…就是一个输出字符串而已

    2022年4月5日
    46
  • SQL 2008 数据库迁移

    SQL 2008 数据库迁移

    2021年12月8日
    39

发表回复

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

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