Then I started thinking: why two concepts, class and module, instead of
only one?
Classes heritage, a feature modules don't have, can be done with include
and extend togheter. So we would need another method that does both
include and extend (call it inherit). Classes can't be used to define a
scope.
Modules can't be instanciated, but classes can.
So why not have only one concept that does both class and modules? You
may call this unified concept either class or a module, I'll call it X.
X is capable of extending, including and inheriting, does scoping and be
instanciated.
That sounds like: We have two different things that behave differently
and serve different purposes. Why don't we replace them by one thing.
Not very convincing to me...
And you forgot to mention: classes can inherit only from a single other
class (a conscious decision by Matz), but you can include many modules.
Seems difficult to unify that in one concept.
Then I started thinking: why two concepts, class and module, instead of
only one?
Classes heritage, a feature modules don't have, can be done with include
and extend togheter. So we would need another method that does both
include and extend (call it inherit). Classes can't be used to define a
scope.
Modules can't be instanciated, but classes can.
So why not have only one concept that does both class and modules? You
may call this unified concept either class or a module, I'll call it X.
X is capable of extending, including and inheriting, does scoping and be
instanciated.
On Wed, Jul 24, 2013 at 1:10 AM, <sto.mar@web.de> wrote:
And you forgot to mention: classes can inherit only from a single other
class (a conscious decision by Matz), but you can include many modules.
Seems difficult to unify that in one concept.
And you forgot to mention: classes can inherit only from a single other
class (a conscious decision by Matz), but you can include many modules.
Seems difficult to unify that in one concept.
And you forgot to mention: classes can inherit only from a single
other
class (a conscious decision by Matz), but you can include many
modules.
Seems difficult to unify that in one concept.
I was alluding to multiple inheritance, meaning a class
inherits _directly_ from more than one superclass.
The point is that inheritance may be done with include + extend from a
module.
In fact, many libraries already prefer include/extend from module than
heritage. See MongoMapper for example.
I still don't understand. I showed that you can inherit from multiple
classes like you can inherit from multiple modules. Yes there are other
differences, but this does not seem to be one of them. Perhaps you think
that modules have some sort of fancier inheritance? If so, this is not the
case. When you include a module, an anonymous class with the module's
methods gets inserted as the superclass.
···
On Wed, Jul 24, 2013 at 7:51 AM, <sto.mar@web.de> wrote:
Am 24.07.2013 14:35, schrieb Josh Cheek:
On Wed, Jul 24, 2013 at 1:10 AM, <sto.mar@web.de >> <mailto:sto.mar@web.de>> wrote:
And you forgot to mention: classes can inherit only from a single
other
class (a conscious decision by Matz), but you can include many
modules.
Seems difficult to unify that in one concept.
You cannot extend from arbitrary classes. If I want to create a class
that extends String and Hash, for example, I can't.
On the other hand I can extend any number of arbitrary modules.
Jesus.
···
On Wed, Jul 24, 2013 at 3:34 PM, Josh Cheek <josh.cheek@gmail.com> wrote:
On Wed, Jul 24, 2013 at 7:51 AM, <sto.mar@web.de> wrote:
Am 24.07.2013 14:35, schrieb Josh Cheek:
On Wed, Jul 24, 2013 at 1:10 AM, <sto.mar@web.de >>> <mailto:sto.mar@web.de>> wrote:
And you forgot to mention: classes can inherit only from a single
other
class (a conscious decision by Matz), but you can include many
modules.
Seems difficult to unify that in one concept.
I was alluding to multiple inheritance, meaning a class
inherits _directly_ from more than one superclass.
I still don't understand. I showed that you can inherit from multiple
classes like you can inherit from multiple modules. Yes there are other
differences, but this does not seem to be one of them. Perhaps you think
that modules have some sort of fancier inheritance? If so, this is not the
case. When you include a module, an anonymous class with the module's
methods gets inserted as the superclass.
And you forgot to mention: classes can inherit only from a
single other
class (a conscious decision by Matz), but you can include
many modules.
Seems difficult to unify that in one concept.
On Wed, Jul 24, 2013 at 7:51 AM, <sto.mar@web.de > <mailto:sto.mar@web.de>> wrote:
Am 24.07.2013 14 <tel:24.07.2013%2014>:35, schrieb Josh Cheek:
On Wed, Jul 24, 2013 at 1:10 AM, <sto.mar@web.de > <mailto:sto.mar@web.de> > <mailto:sto.mar@web.de <mailto:sto.mar@web.de>>> wrote:
differences, but this does not seem to be one of them. Perhaps you think
that modules have some sort of fancier inheritance? If so, this is not
the case. When you include a module, an anonymous class with the
module's methods gets inserted as the superclass.
On Wed, Jul 24, 2013 at 10:25 AM, Jesús Gabriel y Galán < jgabrielygalan@gmail.com> wrote:
On Wed, Jul 24, 2013 at 3:34 PM, Josh Cheek <josh.cheek@gmail.com> wrote:
> On Wed, Jul 24, 2013 at 7:51 AM, <sto.mar@web.de> wrote:
>>
>> Am 24.07.2013 14:35, schrieb Josh Cheek:
>>>
>>> On Wed, Jul 24, 2013 at 1:10 AM, <sto.mar@web.de > >>> <mailto:sto.mar@web.de>> wrote:
>>>
>>>
>>> And you forgot to mention: classes can inherit only from a single
>>> other
>>> class (a conscious decision by Matz), but you can include many
>>> modules.
>>> Seems difficult to unify that in one concept.
>>>
>>>
>>> That seems inaccurate to me:
>>>
>>> C1 = Class.new Object
>>> C2 = Class.new C1
>>> C3 = Class.new C2
>>
>>
>> I was alluding to multiple inheritance, meaning a class
>> inherits _directly_ from more than one superclass.
>>
>
> I still don't understand. I showed that you can inherit from multiple
> classes like you can inherit from multiple modules. Yes there are other
> differences, but this does not seem to be one of them. Perhaps you think
> that modules have some sort of fancier inheritance? If so, this is not
the
> case. When you include a module, an anonymous class with the module's
> methods gets inserted as the superclass.
You cannot extend from arbitrary classes. If I want to create a class
that extends String and Hash, for example, I can't.
On the other hand I can extend any number of arbitrary modules.
They are, the code examples just say otherwise because Ruby lies to you.
It's the same as how the singleton class is actually the object's class,
even though when you ask it about its class, it will tell you what it was
instantiated from.
On Wed, Jul 24, 2013 at 12:54 PM, <sto.mar@web.de> wrote:
Am 24.07.2013 15:34, schrieb Josh Cheek:
> On Wed, Jul 24, 2013 at 7:51 AM, <sto.mar@web.de > > <mailto:sto.mar@web.de>> wrote:
>
> Am 24.07.2013 14 <tel:24.07.2013%2014>:35, schrieb Josh Cheek:
>
> On Wed, Jul 24, 2013 at 1:10 AM, <sto.mar@web.de > > <mailto:sto.mar@web.de> > > <mailto:sto.mar@web.de <mailto:sto.mar@web.de>>> wrote:
>
>
> And you forgot to mention: classes can inherit only from a
> single other
> class (a conscious decision by Matz), but you can include
> many modules.
> Seems difficult to unify that in one concept.
>
>
> That seems inaccurate to me:
>
> C1 = Class.new Object
> C2 = Class.new C1
> C3 = Class.new C2
>
>
> I was alluding to multiple inheritance, meaning a class
> inherits _directly_ from more than one superclass.
>
>
> I still don't understand. I showed that you can inherit from multiple
> classes like you can inherit from multiple modules. Yes there are other
No, they behave differently!
The modules are *not* superclasses of the classes they are mixed into: