literal icon indicating copy to clipboard operation
literal copied to clipboard

Runtime assertions with `binding.assert`

Open joeldrapper opened this issue 2 months ago • 1 comments

This PR introduces a Binding patch that allows you to make assertions about local variables at any point.

def add(a, b)
  binding.assert(a: Numeric, b: Numeric)
  a + b
end

You would ideally include Literal::Types into Object if you wanted to make the best use of this, since otherwise the _ types are not available in the context of an instance.

It would be nice if there was an equally clean way to make assertions about instance variables.

joeldrapper avatar Oct 16 '25 21:10 joeldrapper

Things to consider adding:

  • asserting against instance variables
  • asserting against class variables
  • asserting against global variables

PR also needs some minimal docs explaining how the method works (what error it raises if an assertion fails, what kinds of types you can pass, etc.)

But, this feels like a perfect next step for Literal. I love it

fractaledmind avatar Oct 16 '25 21:10 fractaledmind