2005-01-11
[アイデア]Easy Rocket インターフェース案 (4) 破壊的動作をする + ってのはちょっとどうかと
なかださんからツッコミを頂く。ありがたや。
ただ意味がわからなくて一晩考える。やっとわかった気が。これでよいかな。
class Vector3D < Array
def x ; self[0] ; end
def x=v ; self[0] = v ; end
def +dpos
Vector3D[self[0] + dpos[0], self[1] + dpos[1], self[2] + dpos[2]]
end
end
class Ball
def initialize
@pos = Vector3D[0,0,0]
end
def position
@pos
end
def position=pos
#@pos.replace pos
@pos = Vector3D[*pos]
end
end
ball = Ball.new
x = y = z = 100
dx = 10
dpos = 1, 2, 3
ball.position = x, y, z
ball.position.x = x
ball.position.x += dx
ball.position += dpos
pos = ball.position
x, y, z = ball.position
p pos
p x,y,z