LoginSignup
0
0

More than 5 years have passed since last update.

オブジェクトの同一性

Last updated at Posted at 2016-12-03

メモ

すべてのオブジェクトは「ID」と「値」を持つ。

test.rb
str1 = "foo"
str2 = str1
str3 = "foo"
#equal?はIDか同じかどうか判定する
p str1.equal?(str2)
# =>true
p str1.equal?(str3)
# =>false

p str1.object_id
# =>70338021665000
p str2.object_id
# =>70338021665000
p str3.object_id
# =>70338021664980
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