Open
Description
At the moment, there seems to be no way to abstract def
class methods. This is a bit of a problem, in case you want to guarantee subclasses implement certain constructors! Take this for example:
abstract class Thing
abstract def self.parse(s : String) : Thing
abstract def self.construct_somehow(a : Int, b : String, c : Bool) : Thing
end
Right now, that doesn't work, but instead errors out with the error can't define abstract def on metaclass
. The best way I can come up with to do something similar in the current version of Crystal is this:
abstract class Thing
abstract def self.parse(s : String) : Thing
raise NotImplementedError.new # Or similar
new
end
abstract def self.construct_somehow(a : Int, b : String, c : Bool) : Thing
raise NotImplementedError.new
new
end
end
...But that's runtime (and boilerplate-ey).
I hope there's something I'm missing!