Skip to content

Instantly share code, notes, and snippets.

@henri
Created October 1, 2025 21:25
Show Gist options
  • Save henri/0c0692d90cc3a53aba2d0d35d90acb4a to your computer and use it in GitHub Desktop.
Save henri/0c0692d90cc3a53aba2d0d35d90acb4a to your computer and use it in GitHub Desktop.
negative space programming example snippits
def calculate_area(width, height)
raise TypeError, "Width must be a number" unless width.is_a?(Numeric)
raise TypeError, "Height must be a number" unless height.is_a?(Numeric)
raise ArgumentError, "Width must be positive" unless width > 0
raise ArgumentError, "Height must be positive" unless height > 0
width * height
end
# Usage:
calculate_area(10, 20) # works fine
calculate_area(-5, 10) # raises ArgumentError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment