Module: Vector2d::Coordinates

Included in:
Vector2d, Vector2d
Defined in:
lib/vector2d/coordinates.rb

Overview

Coordinate validation, shared by the class methods that parse input and by the constructor.

Class Method Summary collapse

Class Method Details

.coordinate(value) ⇒ Integer, ...

Returns the value if it is a valid coordinate, raises ArgumentError otherwise. Coordinates are real numbers, so Complex is rejected along with everything outside Numeric.

Parameters:

  • value (Object)

    the value to validate

Returns:

  • (Integer, Float, Rational, BigDecimal)

    the value

Raises:

  • (ArgumentError)


15
16
17
18
19
20
# File 'lib/vector2d/coordinates.rb', line 15

def coordinate(value)
  return value if value.is_a?(Float) || value.is_a?(Integer)
  raise ArgumentError, "not a valid coordinate: #{value.inspect}" unless value.is_a?(Numeric) && value.real?

  value
end