0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rubyの!メソッド名の命名規則について

Posted at

はじめに

昨日聞いたLTの内容がためになったので、忘れる前に備忘録。

rubyのメソッド名につける!について

Rubyで使われる記号の意味(正規表現の複雑な記号は除く)には以下のようにあります。

def xxx!
「!」はメソッド名の一部です。慣用的に、 同名の(! の無い)メソッドに比べて より破壊的 な作用をもつメソッド(例: tr と tr!)で使われます。

trとtr!に注目

!のつくメソッドとつかないメソッドで必ず対になっている。

基本的には厳密にルールが決まっているわけではなく、雰囲気でOK

例外を発生したり、破壊的変更を行う、危険な方のメソッドに!をつける。

おまけ exitとexit!

exit!の方が例外を出さないが!がついている

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?