I
I
Ivan Bogomolov2014-05-18 21:23:47
ruby
Ivan Bogomolov, 2014-05-18 21:23:47

Why is there no abstract class in Ruby?

Maybe someone knows? And is it really a good way to emulate an abstract class?

class AbstractEmulate

def requiredMethod
    #abort() or throw Exception here
end

def requiredMethodTwo
    abort("Please define #{__method__.to_s}")
end

end

respectively, after inheritance if class MyClass < AbstracEmulate , if we do not define methods , we will get errors. Does anyone do this?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey, 2014-05-18
Protko @Fesor

stackoverflow.com/questions/715604/why-do-dynamic-...
Ruby/python doesn't really need abstract classes. In any case, the authors of languages ​​thought so, based on the idea that in these languages ​​all checks for the existence of methods occur at runtime, well, you can replace methods at runtime and do a lot more with classes.

V
Viktor Vsk, 2014-05-18
@viktorvsk

Maybe someone knows? And is it really a good way to emulate an abstract class?

Usually (although, perhaps, just a subjective opinion and there are many advantages in this approach), emulating a feature of the X language / framework in the Y language / framework, following against their conventions, is a bad option.

S
Sergey, 2014-05-18
@mastedm

You can use the gem interface

R
Rinat Zakiryanov, 2016-12-26
@Rinz

Ruby is a language that is pure OOP, so all objects that exist in it are already de facto abstract. in each object in Ruby (and in Ruby EVERYTHING is an object) you can add at runtime, change behavior, destroy a method, override, supplement, and whatever you like, Ruby, like Smalltalk, is a pure OO language and therefore the whole world is for them both an object and abstraction at the same time each object can be augmented, there may be empty objects that are filled in later (same work of abstraction in C# "abstract class")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question