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?

More than 3 years have passed since last update.

破壊的メソッドと非破壊的メソッドの違い

Posted at

破壊的メソッドと非破壊的メソッドの違いをちゃんと理解していなかったためmemoしておく。

非破壊的メソッドとは

gorira = "kojiro"
puts gorira.upcase 
puts gorira
#=>

KOJIRO 

kojiro

レシーバーである、gorira自体の値はそのままkojiroという小文字のままで保持される。

破壊的メソッドとは

それに対して破壊的メソッドはこんな感じ。

gorira = "kojiro"
puts gorira.upcase!
puts gorira
#=>

KOJIRO 

KOJIRO 

レシーバーである、gorira自体の値もKOJIROという大文字に変更してしまうことができる。

こんな感じ。

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?