From: Daniel Bush Date: 2008-11-03T13:20:26+09:00 Subject: Re: Ruby for Philosophers Sebastian Torena wrote: ... > So, what all this got to do with Ruby? Well, I've been thinking about to > learn a second language from scratch. It could be Ruby. And I say could > cause I can't find one document that shows me the foundation. If I not > wrong, in Ruby, everything belongs to one class or another. Then, the > class Class itself must inherit certain characteristics from something > else. Anyway, my question is what leads: 多Where can I find a > documentation that lists and defines all the elements of the class > Class? 多Is it possible to think about learning Ruby as to learn, for > example, chess? If that's true, which are the most basics rules for > playing Ruby? ... I was going to suggest this link: http://www.ruby-doc.org/docs/ProgrammingRuby/html/classes.html as a good starting point (assuming they know ruby). The 2nd paragraph definitely bears a closer reading. I don't know how you'd write philosophy in Ruby, but the ruby universe does seem kind of tidy and self-consistent (putting to one side the dark internals) - I'm sure philosophers like Spinoza, for instance, would have appreciated the structure and maybe taken inspiration from it :) From a pedagogical point of view, wouldn't it be helpful to have a diagram showing how ruby is structured based on Object#class and Class#superclass? I don't mean listing all the in-built classes like File, IO.. etc but just mapping out fundamentally how ruby is structured. This would be trivial to people who do ruby metaprogramming in their sleep, but it might help other people get their heads round classes and object instances and modules etc.. ? My understanding is: All ruby objects have an associated class-like object (see below) courtesy of Object#class. This class gives them their method definitions. Class-like objects have their class set to Class itself. This gives ruby's class-like objects a hierarchy (ie classical inheritance) because Class has the method 'superclass'. Object ends up being at the top of this hierarchy. Putting aside how all this is implemented internally, it seems that Class sets up the idea of "class" and class hierarchy; which allows Object to be given the ultimate superclass status in the ruby universe. Seems like both Object and Class are intertwined a little; with Module sitting between them (just looking at it philosophically from the surface). The diagram I was thinking of would have 3-4 sections with pointers mapping 'class' relationships and 'superclass' relationships. The sections would be something like: 1) Class 2) Class.new, Object, Module, class Foo;...;end, File, IO, ... --------------------------------------------------------------- 3) Module.new, module Bar;...;end, Kernel, ... 4) Object.new, Class.new.new , Foo.new, ... Sections 1 and 2 are the class-like objects whose 'class' is Class (including Class itself) and so have the idea of a superclass hierarchy; . Class itself interestingly is at the bottom of the class hierarchy, followed by Module and then Object at the top. Classes created by us eg Foo have their superclass set by default to Object unless you specify that they inherit from some other class. The diagram bascially splits the ruby universe into two groups: class-like objects (1 and 2) which have a class hierarchy and non class-like objects (3 and 4). 3) is sort of an in-between, halfway house. These objects (ruby modules) resemble classes in 2) but can't be instantiated and don't have class Class and as a result no superclass. Any thoughts? -- Daniel Bush -- Posted via http://www.ruby-forum.com/.