middleclass & extras: middleclass 3.0 is out!

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain

Re: middleclass & extras: middleclass 3.0 is out!

Post by kikito » Fri Aug 01, 2014 3:16 pm

No, I meant that, in Ruby, classes are instances of a class named Class.

I will try to give an example. The code in this post will be all ruby.

Imagine that you create a class named Person.

In ruby, classes have an attribute called name which returns their name (It's a bit magical). So if you do Person.name, you get the string "Person".

Imagine that you create an instance of Person, doing peter = Person.new(). Nothing extraordinary there.

Since it is an instance, peter has a built-in attribute named peter.class. It contains a reference to Person.

But, if you do Person.class, you also get a reference to something - a different class. That's the Class class. You can check it by doing Person.class.name (it returns the string "Class").

In ruby, everything is an object. This means that everything is an instance of some class. Even classes. Even the Class class is an instance of something (it's an instance of itself - nifty stuff).

This is very useful because it means that you can treat classes as objects. You can put them on an array, and call methods on them. You can ask a class "give me your list of methods", and then look for a particular method, and call it. Etc.

What I was trying to say is that I had to let go of that complexity when I built middleclass. Everything on middleclass isn't an object. In particular, classes are not instances of anything, and there is no Class class.

I hope this clarifies things.
Last edited by kikito on Fri Aug 01, 2014 4:16 pm, edited 1 time in total.
When I write def I mean function.

User avatar
Inner party member
Posts: 1562
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)

Re: middleclass & extras: middleclass 3.0 is out!

Post by Roland_Yonaba » Fri Aug 01, 2014 3:48 pm

kikito wrote:I hope this clarifies things.
Hey, I learnt something indeed, here. Awesome.

User avatar
Party member
Posts: 185
Joined: Tue Jun 03, 2014 4:18 pm

Re: middleclass & extras: middleclass 3.0 is out!

Post by murks » Fri Aug 01, 2014 4:18 pm

Thanks, that explains it. I didn't realise that ruby is _that_ weird, but it seems to consequently realize 'everything is an object'.

User avatar
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands

Re: middleclass & extras: middleclass 3.0 is out!

Post by bartbes » Sat Aug 02, 2014 9:13 am

I must have had ruby confused with another language, then, my bad.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests