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

[Ruby] Ruby Variable Scope的更多相关文章

  1. [翻译] Tensorflow中name scope和variable scope的区别是什么

    翻译自:https://stackoverflow.com/questions/35919020/whats-the-difference-of-name-scope-and-a-variable-s ...

  2. [TensorBoard] Name & Variable scope

    TF有两个scope, 一个是name_scope一个是variable_scope 第一个程序: with tf.name_scope("hello") as name_scop ...

  3. tensorflow变量作用域(variable scope)

    举例说明 TensorFlow中的变量一般就是模型的参数.当模型复杂的时候共享变量会无比复杂. 官网给了一个case,当创建两层卷积的过滤器时,每输入一次图片就会创建一次过滤器对应的变量,但是我们希望 ...

  4. PHP Variable Scope

    原文: https://phppot.com/php/variable-scope-in-php/ Last modified on March 24th, 2017 by Vincy. ------ ...

  5. tensorflow variable scope 变量命名空间和变量共享

    import tensorflow as tf def f(): var = tf.Variable(initial_value=tf.random_normal(shape=[2])) return ...

  6. Python中变量的作用域(variable scope)

    http://www.crifan.com/summary_python_variable_effective_scope/ 解释python中变量的作用域 示例: 1.代码版 #!/usr/bin/ ...

  7. JavaScript变量作用域(Variable Scope)和闭包(closure)的基础知识

    在这篇文章中,我会试图讲解JavaScript变量的作用域和声明提升,以及许多隐隐藏的陷阱.为了确保我们不会碰到不可预见的问题,我们必须真正理解这些概念. 基本定义 作用范围是个“木桶”,里面装着变量 ...

  8. Python Variable Scope

    Python中的变量的作用域有时会让像我这样的初学者很头疼. 其实只需要掌握以下两点: 1. Python能够改变变量作用域的代码段是def.class.lamda;    而if/elif/else ...

  9. python variable scope 变量作用域

    python 中变量的作用域经常让我感到很迷 In Python, on the other hand, variables declared in if-statements, for-loop b ...

随机推荐

  1. 【POJ3481】【splay】Double Queue

    Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest ...

  2. 封装Timer

    System.Timers.Timer,System.Timers.Timer在使用的过程中需要: 1.构造函数不同,构造函数可以什么事情也不做,也可以传入响应间隔时间:System.Timers.T ...

  3. cmd 命令行下复制、粘贴的快捷键

    1.单击左下角“开始”菜单,选择“运行”,输入“cmd”. 2.在弹出的cmd窗口的标题栏上点击“右键”,选择“属性”. 3.在弹出的对话框中选择“选项”这个选项卡,在“编辑选项”区域中勾选“快速编辑 ...

  4. 解决mac上Android开发时出现的ADB server didn't ACK

    mac 上adb连接不到android手机可以参考:这里 xxxdeMacPro:~ xxx$ adb start-server * daemon not running. starting it n ...

  5. DOM对象控制HTML无素——详解2

    节点属性 在文档对象模型 (DOM) 中,每个节点都是一个对象.DOM 节点有三个重要的属性 : 1. nodeName : 节点的名称 2. nodeValue :节点的值 3. nodeType ...

  6. meta标签常用属性整理

    在segmentfault看到这篇文章,觉得整理的很详细,所以转载过来和大家分享一下. 原文地址:http://segmentfault.com/blog/ciaocc/119000000240791 ...

  7. C#.NET Winform 通用开发框架

    C/S系统开发框架-企业版 V4.0 (Enterprise Edition) 简介: http://www.csframework.com/cs-framework-4.0.htm 视频下载: 百度 ...

  8. E: Some packages could not be authenticated

    问题:          在Ubuntu上,安装软件时出现了“E: Some packages could not be authenticated”错误. 原因:     表示系统无法验证这个软件包 ...

  9. Oralce 字符串截取

    update E_SYS_STRATEGY set sconfigvalue=(select Substr((select sconfigvalue from E_SYS_STRATEGY where ...

  10. Content related to smartcards (and RFID/NFC)

    Introduction Add your content here. ISO/IEC 7816 Contact Cards Hardware EMV payment cards Orange Cas ...