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


相关推荐

  • pycharm怎么运行django项目_django怎么用

    pycharm怎么运行django项目_django怎么用原文转载自:http://www.cnblogs.com/Leo_wl/p/5824541.html本文面向:有python基础,刚接触web框架的初学者。  环境:windows7   python3.5.1   pycharm专业版   Django1.10版  pip3一、Django简介  百度百科:开放源代码的Web应用框架,由Python语言编写……  

    2022年8月28日
    5
  • PLSQL安装出错

    PLSQL安装出错PLSQL 安装出错输入用户名密码 database 之后报错 解决方法 1 需要安装 oracle 才行 于是安装了 oracle12crel 版本安装过程中需记住以下两个信息 这里将 cdadmin4 改成了 oracle12c 安装完成之后找到 D app oracle12c product 12 1 0 dbhome 1 NETWORK ADMIN 这个 Oracle 的安装路径

    2025年9月28日
    0
  • &与&&的区别

    &与&&的区别

    2021年10月2日
    35
  • VMware下载安装教程_安装vmware虚拟机

    VMware下载安装教程_安装vmware虚拟机全网最详细的VMware虚拟机下载安装教程第一步下载虚拟机1.进入VMware官网,点击左侧导航栏中的下载,选择下拉列表中的产品下载,再点击图中标记的WorkstationPro,如下图所示。2.选择自己需要的版本和操作系统,在这里以Windows系统为例,点击转至下载,如下图所示。-3.点击转至下载后也在此处可以选择版本。选择好版本后点击立即下载。如下图所示。4.注意,需要登录之后才能下载。若无账号可点击注册后登录。如下图所示。二、安装虚拟机1.进入下载路径,双击.

    2025年11月5日
    3
  • 分子动力学模拟软件_材料领域十大常用绘图软件

    作为材料领域的科研工作者,你是否常为如何表达自己的思想而苦恼?作为学术论文创造者,你是否为论文中图文单一而叹气?在这里,GO小妹推荐给你几款常用绘图软件,让你论文从此成为焦点!1——OriginProOringinPro的主要功能为数据分析和绘图。Origin的数据分析主要包括统计、信号处理、图像处理、峰值分析和曲线拟合等各种完善的数学分析功能。进行数据分析时,只需将原始数据粘贴进Origin表格…

    2022年4月3日
    843
  • 虚拟机里查看linux系统的ip地址ifconfig命令显示信息过多导致看不到ip

    虚拟机里查看linux系统的ip地址ifconfig命令显示信息过多导致看不到ip

    2021年5月16日
    139

发表回复

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

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