小写和小写之间的区别!在Ruby中

我只是在学习 Ruby,我不太明白几种 Ruby方法间的差异,有没有’!’最后.有什么不同?为什么我会用另外一个

解决方法

最后有感叹号的方法通常被称为爆炸方法.爆炸方法不一定修改其接收器,并且不保证没有感叹号的方法不会.

这在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.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...