LoginSignup
0
0

More than 3 years have passed since last update.

Ruby 破壊的メソッド 非破壊的メソッド

Posted at

破壊的メソッド、非破壊的メソッドって??

1.破壊的メソッド

オブジェスト自体を変更するメソッドである。
それ以降、オブジェクトは、変更された状態が続く。

2.非破壊的メソッド

オブジェクト自体を変更した場合の値を返すメソッド
以降のプログラム上では、値は元のまま

3.例

例として、
小文字→大文字の破壊的メソッドのupcase!
小文字→大文字の非破壊的メソッドのupcase

str = "abc"
str.upcase!
puts str

実行結果

ABC
str = "abc"
puts str.upcase
puts str

実行結果

ABC
abc
0
0
1

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