带有双下划线的Ruby变量名称 [英] Ruby variable name with double underscores

查看:137
本文介绍了带有双下划线的Ruby变量名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,我看到变量名的开头和结尾都有双下划线.例如:

Sometimes I see variable names with double underscore in the beginning and the end. For example:

Article.__elasticsearch__

在Ruby变量名称中是否存在与双下划线相关的命名约定?

Is there some naming convention related to double underscores in Ruby variable names?

推荐答案

基本下划线或双下划线表示 特殊/避免覆盖"-意味着减少 其他人可能定义的方法/属性的可能性 一样的名字.最常见的是__send__.

An initial underscore or double underscore basically indicates "special/avoid overwrite" --meaning it's meant to reduce the likelihood that someone else might define a method/attribute of the same name. The most common occurrence is __send__.

来自 Ruby论坛

这篇关于带有双下划线的Ruby变量名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆