From: "Mauricio Fernández" Date: 2003-01-23T16:47:33+09:00 Subject: Re: accessors for module instance vars On Thu, Jan 23, 2003 at 01:01:26PM +0900, Gavin Sinclair wrote: > On Thursday, January 23, 2003, 4:08:49 AM, Mauricio wrote: > > > I meant that > > batsman@tux-chan:/tmp$ cat c.rb > > class A; end > > class B < A; end; > > p (B < A) > > p (B.class < A.class) > > batsman@tux-chan:/tmp$ ruby c.rb > > true > > false > > > as both are of class Class. If there was an automatic relationship > > between the classes of the classes, my example wouldn't work. > > > >> class A; end > => nil > >> A < (class << A; self; end) > => false > >> A > (class << A; self; end) > => false > >> A <=> (class << A; self; end) > => 1 > > Can anyone tell me what to make of that? I thought that the singleton > of a class inherited from the class. The operation of "super" within > a singleton implies that. class A; def a; "A#A"; end; end ==>nil class << A; def a; "A.a"; super; end; end ==>nil A.a NameError: super: no superclass method `a' from (irb):7:in `a' from (irb):8 However class A; class << self; def a; p "A.a"; end; end; end ==>nil class B < A; class << self; def a; p "B.a"; super; end; end; end ==>nil A.a "A.a" ==>nil B.a "B.a" "A.a" ==>nil Take a look at the Pickaxe, figure 19.2, p. 244. The singleton doesn't inherit from the class; if it did, all instance methods would become class methods too! As for the starship operator... it cannot return anything meaningful, can it? I mean we cannot assume that A <=> B == 1 => A > B -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com Problem solving under Linux has never been the circus that it is under AIX. -- Pete Ehlke in comp.unix.aix