4 ms·
In pre-Perl 5.12 I've also implemented sub not_impl { die "Not implemented"; } which makes it just a if ($some_clause) { not_impl
by jerf 13y ago
In pre-Perl 5.12 I've also implemented
sub not_impl {
die "Not implemented";
}
which makes it just a
if ($some_clause) {
not_impl;
}
which is pretty close (semicolon optional here). Replace the die with your choice of thrown exception or confess or whatever, of course.
I'm sure Ruby could do something similar. It may be less pretty but it works, and it is useful during certain types of development, I find.
- chromatic 13y agoIt may be less pretty but it works... The primary goal of the `...` feature was to make example code compile safely. (I implemented the feature in Perl 5.)
- jerf 13y agoOh, yes, of course it doesn't do that, but it's still a useful thing. It's so short it hardly seems worth talking about, but, hey, I went a long time without using such a simple technique myself, so it probably is.
- izietto 13y agoIndeed: def not_impl(reason = 'unknown reason') raise NotImplementedError.new reason end not_impl #=> NotImplementedError: unknown reason not_impl 'TODO' #=> NotImplementedError: TODO You can even define a "..." method: define_method("...") { raise NotImplementedError } send "..." #=> NotImplementedError: NotImplementedError But, as chromatic said, the point is the three dots operator feature