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.
middleclass & extras: middleclass 3.0 is out!
- 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!
Last edited by kikito on Fri Aug 01, 2014 4:16 pm, edited 1 time in total.
When I write def I mean function.
- 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!
Hey, I learnt something indeed, here. Awesome.kikito wrote:I hope this clarifies things.
Re: middleclass & extras: middleclass 3.0 is out!
Thanks, that explains it. I didn't realise that ruby is _that_ weird, but it seems to consequently realize 'everything is an object'.
- 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!
I must have had ruby confused with another language, then, my bad.
Who is online
Users browsing this forum: No registered users and 5 guests