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


相关推荐

  • webgame开发简明教程

    webgame开发简明教程 webgame开发简明教程(1)研究所有点缺乏资料啊。讨论的问题怪怪的。只有很少是能用到的。一、简单的程序框架。webgame程序构成:三大部分。第一是数据流程。第二是程序。第三是美术。其中,数据流程包括了功能。也只有在功能中才能体现数据流程。数据流程相当的麻烦,后面再讨论。比如最简单的卖买产品。要实现这个功能。那么需要有产品基础表、产

    2022年5月2日
  • app漏洞检测方法有哪些_安卓app漏洞挖掘

    app漏洞检测方法有哪些_安卓app漏洞挖掘根据国内专业PP漏洞检测平台爱内测(www.detect.cn)介绍,目前关于APP漏洞检测有以下6种功能检测方法: 组件安全检测对四大组件和WebView的规范使用检测分析,发现因为程序中不规范使用导致的组件漏洞。 代码安全检测对dex和so库以及第三方加载库的代码的安全处理进行检测分析,发现代码被反编译和激活成功教程的漏洞。 内存安全检测检测APP运行过程中的内存处理和保护机制进行检测分析…

    2022年10月28日
  • 3042b什么意思_XC3042

    3042b什么意思_XC3042Loj #3042. 「ZJOI2019」麻将

    2022年4月22日
  • 二进制除法_111011001÷1011二进制除法

    二进制除法_111011001÷1011二进制除法题目描述: 二进制数nmodm的结果是多少?对于二进制数的取模运算,我们的第一反应一定是模拟其减法运算,然后逐位相减。但是这道题的数据达到了$2e5$,鉴于减法模拟的巨大常数,一定是会

    2022年8月4日
  • Dashboard介绍

    Dashboard介绍

    2021年8月20日
  • ajaxpro 原理[通俗易懂]

    ajaxpro 原理[通俗易懂]应当承认我这人实在算不上弄潮儿,Ajax早已流行得一塌糊涂,我却始终没有来研究一下这个东东。上次做网站的时候,BOSS就跟我讲过,可以参考一下Ajax的技术,我嘴上答应,心里却不是十分的在乎。究其原因,一来是我这人比较固步自封,二来起初确实也没太相信Ajax真有BO

    2022年7月12日

发表回复

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

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