LoginSignup
0
0

More than 3 years have passed since last update.

rubyで簡単に基本型と参照型を感じる2

Last updated at Posted at 2020-10-25

rubyで簡単に基本型と参照型を感じる のメソッドを使わないパターンです。

macのターミナルでRubyを起動

   irb

参照型の値のもつ基本型の値を変更した場合

temp=[1,2]
temp2=temp
temp2[0]=11
temp #[11, 2]

tempとtemp2の持つ値(参照値)は同じ

参照型の値そのものを変更した場合

temp=[1,2]
temp2=temp
temp2=11
temp #[1, 2]

tempとtemp2の持つ値(参照値)は異なる

0
0
2

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