[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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 查看首选DNS服务器地址

    查看首选DNS服务器地址查询DNS设置地址1、打开开始菜单里的‘运行’。2、在运行窗口里,输入cmd,打开命令行窗口。3、打开命令行窗口后,输入inconfig/all命令,按回车键。4、输入后,就可以看到自己电脑的IP地址和DNS服务器地址了。…

    2022年6月11日
    58
  • C# List去重的三种方法「建议收藏」

    C# List去重的三种方法「建议收藏」三种去重的方法1、List中的元素实现IEquatabe接口,并提供Equals方法和GetHashCode方法。2、使用表达式users.Where((x,i)=>users.FindIndex(z=>z.name==x.name)==i)去重,这条语句是查找users中name等于x.name的第一个元素。经实验,这个方法效率最低。3、使用循环,判断每个元素是否重复

    2022年5月25日
    920
  • 爱的最高境界

    爱的最高境界

    2021年7月26日
    66
  • 史上最简单的 MyBatis 教程(一)

    史上最简单的 MyBatis 教程(一)1简介MyBatis是支持普通SQL查询,存储过程和高级映射的优秀持久层框架,其几乎消除了所有的JDBC代码和参数的手工设置以及结果集的检索。MyBatis使用简单的XML或注解用于配置和原始映射,将接口和Java的POJOs(PlainOldJavaObjects,普通的Java对象)映射成数据库中的记录。MyBatis应用程序大都使用SqlSessionFac

    2022年10月26日
    0
  • STM32CubeMX介绍、下载与安装

    STM32CubeMX介绍、下载与安装推荐分享一个大神的人工智能教程。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到人工智能的队伍中来!http://www.captainbed.net/strongerhuang本教程今年更新了部分内容:STM32CubeMX系列教程Ⅰ、写在前面相信很多人都知道STM32CubeMX这个工具,也是近年来开发STM32比较流行的一个工具。这个工具从两年…

    2022年6月12日
    40
  • spark中flatMap函数用法–spark学习(基础)「建议收藏」

    spark中flatMap函数用法–spark学习(基础)「建议收藏」说明在spark中map函数和flatMap函数是两个比较常用的函数。其中map:对集合中每个元素进行操作。flatMap:对集合中每个元素进行操作然后再扁平化。理解扁平化可以举个简单例子valarr=sc.parallelize(Array((“A”,1),(“B”,2),(“C”,3)))arr.flatmap(x=>(x._1+x._2)).foreach(println)输出

    2022年5月27日
    30

发表回复

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

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