[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 ...
随机推荐
- python everything is object
python面向对象非常彻底,即使过程式的代码风格,python在运作的时候也是面向对象的.everything is object. 差异 在面向对象的理念上,python和非常工程化的面向对象语言 ...
- 15_RHEL7挂载NTFS分区
1.下载ntfs-3g wget https://tuxera.com/opensource/ntfs-3g_ntfsprogs-2015.3.14.tgz 2.安装 tar -zxvf ntfs-3 ...
- 使用Thinkphp框架开发移动端接口
本文给大家分享的是使用thinkphp框架开发移动端接口的2种方法,一种是开发API,另外一种是实现移动端访问自动切换移动主题模板,从而实现伪app访问,下面我们就来详细看下如何实现吧. 方案一:给 ...
- Code::Blocks 的配色方案
codeblocks的配置文件是default.conf, 在Windows系统下,该文件在C:\Documents and Settings\Administrator\Application Da ...
- Resilio-sync auto restart
syncheck.sh #!/bin/sh if [ $(pgrep xxxrslsync) ]; then echo && date >> /home/pi/sync/s ...
- 生成mif文件的几种方法总结
mif文件就是存储器初始化文件,即memory initialization file,用来配置RAM或ROM中的数据.生成QuartusII11.0可用的mif文件,有如下几种方式: 方法1:利用Q ...
- Unity3d 随机地图生成
2D解析图: 3D地形: 嘿嘿.
- hadoop2.2.0 单机伪分布式(含64位hadoop编译) 及 eclipse hadoop开发环境搭建
hadoop中文镜像地址:http://mirrors.hust.edu.cn/apache/hadoop/core/hadoop-2.2.0/ 第一步,下载 wget 'http://archive ...
- PYTHON之批量文件指定字符串替换
在工作应用中,运维自动化的基础是标准化. 而标准化的工作,是难点,在公司相关部门的配合. 那么,在有标准化之后,相应的部署脚本,就比较好写了. 贡献一个在类似环境下可以运用的东东.. 当然,可以写得更 ...
- 【Java&Android开源库代码剖析】のandroid-smart-image-view
Android应用开发已经进入到相对成熟的阶段,特别在国外,涌现出了各式各样的成熟稳定的开源库,供普通开发者使用.这种情况虽然极大加速了app开发的进程,但同时带来的问题是大多数普通开发者在使用这些开 ...