Skip to content

Instantly share code, notes, and snippets.

@nagachika
Created September 5, 2020 07:09
Show Gist options
  • Save nagachika/f64241f526a4e4b45cf75ef6961c25dd to your computer and use it in GitHub Desktop.
Save nagachika/f64241f526a4e4b45cf75ef6961c25dd to your computer and use it in GitHub Desktop.
mmc question
class Vector
attr_accessor :x, :y, :z
def initialize(x, y, z)
@x = x
@y = y
@z = z
end
def add(v)
Vector.new(self.x+v.x, self.y+v.y, self.z+v.z)
end
def +(v)
self.add(v)
end
end
def main
a = Vector.new(0, 1, 2)
b = Vector.new(3, 4, 5)
print(a.add(b)) # <- ここの結果の Vector はスタックに確保するよう書き換えられる
print(a + b) # <- この a+b の結果の Vector は?
nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment