[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 |
[Ruby] Ruby Variable Scope的更多相关文章
- [翻译] Tensorflow中name scope和variable scope的区别是什么
翻译自:https://stackoverflow.com/questions/35919020/whats-the-difference-of-name-scope-and-a-variable-s ...
- [TensorBoard] Name & Variable scope
TF有两个scope, 一个是name_scope一个是variable_scope 第一个程序: with tf.name_scope("hello") as name_scop ...
- tensorflow变量作用域(variable scope)
举例说明 TensorFlow中的变量一般就是模型的参数.当模型复杂的时候共享变量会无比复杂. 官网给了一个case,当创建两层卷积的过滤器时,每输入一次图片就会创建一次过滤器对应的变量,但是我们希望 ...
- PHP Variable Scope
原文: https://phppot.com/php/variable-scope-in-php/ Last modified on March 24th, 2017 by Vincy. ------ ...
- tensorflow variable scope 变量命名空间和变量共享
import tensorflow as tf def f(): var = tf.Variable(initial_value=tf.random_normal(shape=[2])) return ...
- Python中变量的作用域(variable scope)
http://www.crifan.com/summary_python_variable_effective_scope/ 解释python中变量的作用域 示例: 1.代码版 #!/usr/bin/ ...
- JavaScript变量作用域(Variable Scope)和闭包(closure)的基础知识
在这篇文章中,我会试图讲解JavaScript变量的作用域和声明提升,以及许多隐隐藏的陷阱.为了确保我们不会碰到不可预见的问题,我们必须真正理解这些概念. 基本定义 作用范围是个“木桶”,里面装着变量 ...
- Python Variable Scope
Python中的变量的作用域有时会让像我这样的初学者很头疼. 其实只需要掌握以下两点: 1. Python能够改变变量作用域的代码段是def.class.lamda; 而if/elif/else ...
- python variable scope 变量作用域
python 中变量的作用域经常让我感到很迷 In Python, on the other hand, variables declared in if-statements, for-loop b ...
随机推荐
- PHP 用Class构造JSON数据
header('Content-type: appliction/json; charset=shift-JIS'); // error //{ // "result": fals ...
- dedecms自定义表单提交成功如何返回当前页面
在plus/diy.php找到showmsg($bkmsg, $goto);改成showmsg($bkmsg, -1);
- QTP插入Output Value和插入CheckPoint,注意点
1. 必须打开程序才能进行Output value和CheckPoint的插入. 2. 也有可能是对象获取不到,从新加载对象库. 提示如下图:
- python之加密
import hashlib obj = hashlib.md5(bytes('adfasfasdfsfasf',encoding = 'utf-8')) obj.update(bytes('123' ...
- objective-c基础教程
command+shift+c foundation框架包含的头文件 /system/library/frameworkks/foundation.framework/headers/
- Linux学习2
第三讲Linux常用命令04 压缩:gzip: 1.只能压缩文件,不能压缩目录 2.不保留源文件 解压缩:gunzip gzip -d ------------------------------ ...
- CMD模块定义规范
CMD 模块定义规范 在 Sea.js 中,所有 JavaScript 模块都遵循 CMD(Common Module Definition) 模块定义规范.该规范明确了模块的基本书写格式和基本交互规 ...
- Unity3d ngui基础教程
Unity3d ngui基础教程 NGUI教程:步骤1-Scene 1.创建一个新的场景(New Scene).2.选择并删除场景里的MainCamera.3.在NGUI菜单下选择Create a N ...
- SetTimer and CreateWaitableTimer的例子(静态函数设置为回调函数,瑞士的网页,有点意思)
Timers (SetTimer and CreateWaitableTimer) in Windows SetTimer The following example creates a time ...
- java学习面向对象构造函数
在java当中目前我们学到的一个比较特殊的函数就是main函数,他是JVM执行的入口,所以书写的格式是固定的,现在我们来介绍java中另一个比较特殊的函数: 构造函数:构造对象的时候调用的函数,作用, ...