A
A
anasasiakiri4enko2016-11-04 00:36:25
Ruby on Rails
anasasiakiri4enko, 2016-11-04 00:36:25

Who will explain the essence of inheritance and mixins in ruby?

Goodnight.
Please explain, otherwise it's a little mess in my head.
1. Mixins help Ruby do multiple inheritance, right?
2. Ruby doesn't have multiple inheritance by default, right?
- 2.1 For example: I have Class A with a million methods, I create class B and inherit from class A, and automatically in class B this million methods, then I create class C and inherit from class B, and automatically I have a class C has the same million methods (as I understand it from class B. Same?). I don’t understand something, isn’t this multiple inheritance ??
3. For example, I create class A, and connect the ivan module (included in class A), in the ivan module I create a function, for example, get_age, and I create it like this Ivan.get_age, (and this is a type of mixin, do I understand correctly? or in another way namespace) and in class A this mixin will be available to me as follows Ivan::get_age. And if I then create class B and inherit from A, and, in class B, the Ivan:: get_ivan method will be unavailable (is this true?)
Sorry, I'm paranoid (

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
anasasiakiri4enko, 2016-11-05
@anasasiakiri4enko

Answer found.

K
Kirill Nesmeyanov, 2016-11-04
@SerafimArts

1. Not really, mixins are not full-fledged "entities", they are pieces of logic, helpers, if otherwise. The User model, for example, is an object, and the Authentication mixin extends that user's capabilities without being anything specific, it just provides the `User.login?` methods. Well, this is for example =)
2. Multiple inheritance, A is inherited from B and C at the same time: `class A < B and C` (pseudo-syntax). In this case, calling super should call methods B and C at the same time, and not follow the inheritance chain from A < B < C. That is, multiple inheritance doesn't have any explicit hierarchy, which is why it doesn't exist.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question