ruby - downcase 和 downcase 的区别!在 ruby

标签 ruby naming-conventions

我刚刚开始学习 Ruby,我不太了解带和不带 '!' 的几种 Ruby 方法之间的区别。在最后。有什么不同?为什么我要使用一个而不是另一个?

最佳答案

末尾带有感叹号的方法通常称为 bang-methods。 bang 方法不一定会修改其接收者,也不能保证没有感叹号的方法不会。

这一切在 this blog post 中都有很好的解释。 .引用帖子:

The ! in method names that end with ! means, “This method is dangerous”—or, more precisely, this method is the “dangerous” version of an otherwise equivalent method, with the same name minus the !. “Danger” is relative; the ! doesn’t mean anything at all unless the method name it’s in corresponds to a similar but bang-less method name.

The ! does not mean “This method changes its receiver.” A lot of “dangerous” methods do change their receivers. But some don’t. I repeat: ! does not mean that the method changes its receiver.

关于ruby - downcase 和 downcase 的区别!在 ruby ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/709229/

相关文章:

python - 我应该用 Python 命名我的全局模块?

clojure - clojure/clojurescript 中单个 var 命名空间的命名约定是什么?

ruby - 无法在 MAC OS X 上安装或运行 OpenShift RHC 客户端工具

ruby - 什么是更聪明的选择 : Ruby logic or SQL function?

naming-conventions - 非常长的类/变量/属性/方法名称

Wcf 服务代理名称/命名空间命名策略

java - setter/getter 的正确命名约定

ruby - 来自 Shopify Liquid 的 API 调用

ruby-on-rails - vim/macvim : locate where a method/symbol is defined

ruby - 我如何匹配所有 % 除了后跟 s 的百分比?