literal
literal copied to clipboard
Runtime assertions with `binding.assert`
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.
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