Skip to content

Instantly share code, notes, and snippets.

@xenobrain
Created November 16, 2022 23:22
Show Gist options
  • Save xenobrain/e3d603ae6c7a7c0211551fd8b42074d8 to your computer and use it in GitHub Desktop.
Save xenobrain/e3d603ae6c7a7c0211551fd8b42074d8 to your computer and use it in GitHub Desktop.
DragonRuby MatrixFunctions monkey patch
module Vec2Extensions
def + other
return super other if other.is_a? Vec2
vec2 x + other, y + other if other.is_a? Numeric
end
def - other
return vec2 x - other.x, y - other.y if other.is_a? Vec2
vec2 x - other, y - other if other.is_a? Numeric
end
def * other
return super other if other.is_a? Vec2
vec2 x * other, y * other if other.is_a? Numeric
end
def / other
vec2 x / other, y / other if other.is_a? Numeric
end
end
class Vec2
prepend Vec2Extensions
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment