Skip to content

Commit

Permalink
Type checking is added in Vector.coerce method
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Vartanov committed Nov 4, 2008
1 parent ecafddf commit 89a290b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/vector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ def *(scalar)
Vector.new(x * scalar, y * scalar)
end

def coerce(scalar)
[self, scalar]
def coerce(scalar)
if scalar.is_a?(Numeric)
[self, scalar]
else
raise ArgumentError, "Cannot coerce #{scalar.inspect}"
end
end
end
end

0 comments on commit 89a290b

Please sign in to comment.