[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)
上一篇 2022年2月2日 上午6:00
下一篇 2022年2月2日 上午7:00


相关推荐

  • claude code 安装教程

    claude code 安装教程

    2026年3月16日
    2
  • 《前端运维》二、Nginx–2请求处理流程及核心模块

    前一篇内容,我们学习了nginx的一些基本概念、安装和目录的作用。这篇文章我们来学习一些更加深入的内容。一、Nginx请求处理流程我们先来看张图吧:我们看上图,首先客户端请求到Nginx服务器,

    2022年3月25日
    124
  • 【Oracle错误】unable to connect 08004 ora12154

    【Oracle错误】unable to connect 08004 ora12154从网上得知,oracle有个bug:连oracle的程序exe的路径中如果包含(、还有啥特殊字符的时候,就连不上,报错误ora12154。我今天也遇到了,我在EA连oracle的时候,死活要报这个错,后来把EA的安装目录从C:\ProgramFiles(x86)中剪贴到没有()的地方,就可以了。参考链接:http://www.2cto.com/database/201

    2022年7月24日
    17
  • 推理服务API V2

    推理服务API V2

    2026年3月12日
    2
  • 浅谈Android指纹识别技术[通俗易懂]

    浅谈Android指纹识别技术[通俗易懂]浅谈Android指纹识别技术当今时代,随着移动智能手机的普及,指纹解锁早已是手机不可或缺的一个功能。除了现在比较新款的iPhone或者部分手机采用了FaceID之外,人们几乎天天都会用到指纹解锁技术。但你知道指纹解锁技术背后的原理吗?原理指纹识别的前提是对指纹的采集,所以我们首先就应该了解第一步:指纹采集。第一步:指纹采集指纹采集主要分为两种方式:滑动式采集和按压式采集滑动式采集是将手指在传感器上滑过,从而使手机获得手指指纹图像。滑动式采集具有成本相对偏低,而且可以采集大面积图像的优势。但这

    2022年8月10日
    3
  • 忽略特殊文件

    忽略特殊文件

    2021年10月20日
    46

发表回复

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

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