Created
February 7, 2014 13:08
-
-
Save patricksrobertson/8862336 to your computer and use it in GitHub Desktop.
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 | |
def initialize(x, y) | |
@x, @y = x, y | |
end | |
def *(value) | |
self.class.new(@x * value, @y * value) | |
end | |
def to_s | |
"#{@x}, #{@y}" | |
end | |
def coerce(other) | |
[self, other] | |
end | |
end | |
v = Vector.new(3, 5) | |
puts v | |
puts v * 3 | |
puts 3 * v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment