This file contains hidden or 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
# Add to config/initializers/enumerable.rb | |
module Enumerable | |
NonUniqueError = Class.new StandardError | |
NoElementError = Class.new StandardError | |
def take_first! | |
unless one? | |
if count.zero? | |
raise NoElementError.new('Must have exactly one element, but none found.') | |
else | |
raise NonUniqueError.new('Must have exactly one element, but multiple found.') |
This file contains hidden or 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
import numpy as np | |
class Point(np.ndarray): | |
""" | |
n-dimensional point used for locations. | |
inherits +, -, * (as dot-product) | |
> p1 = Point([1, 2]) | |
> p2 = Point([4, 5]) | |
> p1 + p2 |