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


相关推荐

  • node+express操作cookie「建议收藏」

    node+express操作cookie「建议收藏」Cookie:有时也用其复数形式Cookies。类型为“小型文本文件”,是某些网站为了辨别用户身份,进行Session跟踪而储存在用户本地终端上的数据(通常经过加密),由用户客户端计算机暂时或永久保存的信息。用node操作cookie我们需要cookie-parser模块npmicookie-parser-s接下来在我们的文件中引入此模块//引入express模块constexpress=require(‘express’)//实例化expressconstapp=

    2022年7月11日
    17
  • 多少行代码可以申请软件著作权_python申请软件著作权

    多少行代码可以申请软件著作权_python申请软件著作权在申请软件专利或著作权时,如何快速统计源码行数。其实我们可以利用vs2010的文件搜索功能结合正则表达式,来遍历所有文件得出总行数.

    2022年9月22日
    3
  • 服务器磁盘配置信息,服务器磁盘阵列配置

    服务器磁盘配置信息,服务器磁盘阵列配置说到磁盘阵列(RAID,RedundantArrayofIndependentDisks),现在几乎成了网管员所必须掌握的一门技术之一,特别是中小型企业,因为磁盘阵列应用非常广泛,它是当前数据备份的主要方案之一。然而,许多网管员只是在各种媒体上看到相关的理论知识介绍,却并没有看到一些实际的磁盘阵列配置方法,所以仍只是一知半解,到自己真正配置时,却无从下手。本文要以一个具体的磁盘阵列配置方法…

    2022年6月6日
    54
  • 汇编语言之Debug教程篇

    参考书籍《汇编语言》——王爽Debug的命令比较多,这里我介绍常用的命令,其余的等需要的时候再进行查询。命令用途Debug-R查看、改变CPU寄存器的内容Debug-D查看内存中的内容Debug-E改写内存中的内容Debug-U将内存中的机器指令翻译成汇编指令Debug-T执行一条机器指令…

    2022年4月16日
    47
  • flume使用教程_三阶魔方初级入门教程详细图解

    flume使用教程_三阶魔方初级入门教程详细图解文章目录1.Flume概述1.1Flume定义1.Flume概述1.1Flume定义  

    2025年8月1日
    1
  • 解决 ERROR: Command errored out with exit status 128: git clone -q

    解决 ERROR: Command errored out with exit status 128: git clone -q在安装git+github网页时出现此错误,全称是ERROR:Commanderroredoutwithexitstatus128:gitclone-qhttps://github.com/ildoonet/pytorch-gradual-warmup-lr.git/tmp/pip-req-build-88ue_mqlCheckthelogsforfullcommandoutput.参考解决方案https://github.com/spdx/spdx-onl

    2022年7月21日
    108

发表回复

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

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