[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 ...
随机推荐
- Java学习----对象间的继承
继承:子类可以使用父类非私有的成员变量和方法 public class Father { public String name; public String bloodType; private in ...
- 算法系列之图--BFS
广度优先搜索以源结点s为出发点,算法始终将已发现和未发现结点之间的边界,沿其广度方向向外扩展.也即算法需要在发现所有距离源结点s为k的所有结点之后才会去发现距离源结点距离为k+1的其他结点. talk ...
- WCF返回JSON的详细配置
开发环境:VS2008,c# 1.新建个WCF服务网站 文件-新建-网站-WCF服务 2,运行一下,提示配置WEB.CONFIG,点击确认. 3,打开web.config增加如下节点: <ser ...
- C程序设计语言练习题1-16
练习1-16 修改打印最长文本行的程序的主程序main,使之可以打印任意长度的输入行的长度,并尽可能多地打印文本. 代码如下: #include <stdio.h> // 包含标准库的信息 ...
- Redmine配置
官网步骤说明 http://www.redmine.org/projects/redmine/wiki/RedmineInstall 搭环境 1.MySql 2.RailsInstaller:Redm ...
- duplicate symbols for architecture arm64 (Xcode error)
比如 duplicate symbol _NewBase64Encode_soomla in: /Users/UnityGame/Libraries/Plugins/iOS/Soomla/libSoo ...
- shell命令记录一些
ps aux | sort -k 5n|tail -5 找到内存最对的进程 ps aux 是找出全部的进程 sort -k 5n 表示第5个参数进行排序 tail -5 表示最后5个 ps -e - ...
- 【Java】对Web Service的理解
WSDL(Web Service Description Language)是描述Web Service的语言. 你会怎样向别人介绍你的Web service有什么功能,以及每个函数调用时的参数呢?你 ...
- Frequent values
poj3368:http://poj.org/problem?id=3368 题意:给你一个非下降的序列,然后查询[l,r]内出现最多数字的次数. 题解:首先,因为序列是非下降的,所以相同的数字出现在 ...
- WebService引擎Axis2完美教程
1.http://wenku.baidu.com/link?url=O05r69TGaLmrJrjJqGz-5EASox8FhhUO6i97xoUOV2dcbh8BEnOlX2EN3nuYGE_3HE ...