Skip to content

Instantly share code, notes, and snippets.

@henri
Created October 1, 2025 21:25
Show Gist options
  • Select an option

  • Save henri/0c0692d90cc3a53aba2d0d35d90acb4a to your computer and use it in GitHub Desktop.

Select an option

Save henri/0c0692d90cc3a53aba2d0d35d90acb4a to your computer and use it in GitHub Desktop.

Revisions

  1. henri created this gist Oct 1, 2025.
    13 changes: 13 additions & 0 deletions ruby-negative-space.ruby
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    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