Created
September 5, 2020 07:09
-
-
Save nagachika/f64241f526a4e4b45cf75ef6961c25dd to your computer and use it in GitHub Desktop.
mmc question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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