[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,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
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/115614.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Css中写RGB颜色

    Css中写RGB颜色在Css样式中写RGB颜色样式:

    2022年6月13日
    28
  • 【mysql】explain介绍[通俗易懂]

    【mysql】explain介绍[通俗易懂]【mysql】explain介绍

    2022年4月25日
    35
  • 什么是UE4_unity3d和ue4区别

    什么是UE4_unity3d和ue4区别对于游戏的来说,最能够影响它的性能的,便是游戏程序的开发、维护工作了。游戏开发、维护工作都是通过游戏开发引擎来完成的,而U3D和UE4正是如今行业主流的两款游戏开发引擎。不同的游戏开发引擎在不同的游戏中使用,那么具体的u3d和ue4的区别是什么?小编常被想要进入游戏行业的同学问到,学U3D和UE4哪个更好?其实这主要是看你自己的就业倾向。下面小编就从两款游戏开发引擎的具体区别来讲讲我们该如何选择。…

    2022年10月4日
    0
  • httprunner3源码解读(2)models.py「建议收藏」

    httprunner3源码解读(2)models.py「建议收藏」源码目录结构我们首先来看下models.py的代码结构我们可以看到这个模块中定义了12个属性和22个模型类,我们依次来看属性源码分析importosfromenumimportEnu

    2022年7月29日
    18
  • 风控模型基本概念和方法

    风控模型基本概念和方法每每以为攀得众山小,可、每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~———————————————————————————本笔记源于CDA-DSC课程,由常国珍老师主讲。该训练营第一期为风控主题,培训内容十分紧凑,非常好,推荐:CDA数据科学家训练营———————…

    2022年4月29日
    60
  • 动态规划背包问题(例题)

    动态规划背包问题(例题)发生的方式

    2022年7月26日
    12

发表回复

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

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