Elixir has a similar concept with doc tests:
https://elixir-lang.org/getting-started/mix-otp/docs-tests-a...
You're comments/docs for the method can have demonstration code that is executed when you run your tests, ensuring your docs remain accurate.
It's a great pattern.