middleclass & extras: middleclass 3.0 is out!

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

Re: middleclass & extras: middleclass 3.0 is out!

Post by kikito »

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
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: middleclass & extras: middleclass 3.0 is out!

Post by Roland_Yonaba »

kikito wrote:I hope this clarifies things.
Hey, I learnt something indeed, here. Awesome.
User avatar
murks
Party member
Posts: 185
Joined: Tue Jun 03, 2014 4:18 pm

Re: middleclass & extras: middleclass 3.0 is out!

Post by murks »

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
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: middleclass & extras: middleclass 3.0 is out!

Post by bartbes »

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

Who is online

Users browsing this forum: Bing [Bot] and 2 guests