Skip to content

Instantly share code, notes, and snippets.

@patricksrobertson
Created February 7, 2014 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patricksrobertson/8862336 to your computer and use it in GitHub Desktop.
Save patricksrobertson/8862336 to your computer and use it in GitHub Desktop.
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