ruby operator overloading question
问题 i've been messing around with ruby and opengl for entertainment purposes, and i decided to write some 3d vector/plane/etc classes to pretty up some of the math. simplified example: class Vec3 attr_accessor :x,:y,:z def *(a) if a.is_a?(Numeric) #multiply by scalar return Vec3.new(@x*a, @y*a, @z*a) elsif a.is_a?(Vec3) #dot product return @x*a.x + @y*a.y + @z*a.z end end end v1 = Vec3.new(1,1,1) v2 = v1*5 #produces [5,5,5] which all fine and dandy, but i also want to be able to write v2 = 5*v1