no. the new behaviour is fine - i was simply describing how it is now
and how
that relates to the 'infinite levels' issue in that i think it's
strange -
but consistent. believe me - you've no idea how much easier my trait lib
would have been to write if
child.singleton_class < parent.singleton_class
Well it would be nice if this were true, but it's not - "higher order"
singleton class
behavior changed quite a bit in the past and it so again from 1.82 to
todays cvs.
Lionel point was because Ruby does not seem to have a consistent treatment
(consitency is always relative to the reades eyes) of these "higher
order" singleton
classes, they should be forbidden in the first place. I ran the
following script
with a standard 1.82, todays cvs.
----
puts RUBY_VERSION
public # create meta objects
def m(height =1)
height.zero? ? self : class << self; self end.m(height -1)
end
base = [Object,Module, Class]
require 'enumerator'
(0..11).each_cons(2) do |a,b|
d0,r0 = a.divmod(3)
d1,r1 = b.divmod(3)
rel = base[r0].m(d0) > base[r1].m(d1)
puts "#{base[r0]}.m(#{d0}) > #{base[r1]}.m(#{d1}) # #{rel}"
end
class A; end
class B < A; end
def q(s)
puts s << " # #{eval(s)}"
end
puts "\n###","\n"
q "B.new.m(5) < B.m(4)"
q "B.m(4) < A.m(4)"
q "A.m(4) < Object.m(4)"
puts "\n### print superclass chain","\n"
class Class
alias succ superclass
end
(1..8).each do |i|
puts ((B.new.m(i)..Object).to_a.join(" : "))
end
---
These were the two outputs
---
1.9.0
Object.m(0) > Module.m(0) # true
Module.m(0) > Class.m(0) # true
Class.m(0) > Object.m(1) # true
Object.m(1) > Module.m(1) # true
Module.m(1) > Class.m(1) # true
Class.m(1) > Object.m(2) # false
Object.m(2) > Module.m(2) # false
Module.m(2) > Class.m(2) # false
Class.m(2) > Object.m(3) # true
Object.m(3) > Module.m(3) # false
Module.m(3) > Class.m(3) # false
###
B.new.m(5) < B.m(4) # true
B.m(4) < A.m(4) # false
A.m(4) < Object.m(4) # false
### print superclass chain
#<Class:#<B:0x101030a0>> : B : A : Object
Class : Module : Object
#<Class:Class> : #<Class:Module> : #<Class:Object> : Class : Module : Object
Class : Module : Object
#<Class:Class> : #<Class:Module> : #<Class:Object> : Class : Module : Object
Class : Module : Object
#<Class:Class> : #<Class:Module> : #<Class:Object> : Class : Module : Object
Class : Module : Object
---
and
---
1.8.2
Object.m(0) > Module.m(0) # true
Module.m(0) > Class.m(0) # true
Class.m(0) > Object.m(1) # true
Object.m(1) > Module.m(1) #
Module.m(1) > Class.m(1) # true
Class.m(1) > Object.m(2) # true
Object.m(2) > Module.m(2) #
Module.m(2) > Class.m(2) #
Class.m(2) > Object.m(3) #
Object.m(3) > Module.m(3) #
Module.m(3) > Class.m(3) #
###
B.new.m(5) < B.m(4) #
B.m(4) < A.m(4) #
A.m(4) < Object.m(4) #
### print superclass chain
#<Class:#<B:0x2793bc8>> : B : A : Object
#<Class:#<Class:#<B:0x2793a60>>> : #<Class:B> : #<Class:A> :
#<Class:Object> : Class : Module : Object
#<Class:#<Class:#<Class:#<B:0x2793820>>>> : #<Class:Class> :
#<Class:Module> : #<Class:Object> : Class : Module : Object
#<Class:#<Class:#<Class:#<Class:#<B:0x2793598>>>>> : #<Class:Class> :
#<Class:Module> : #<Class:Object> : Class : Module : Object
#<Class:#<Class:#<Class:#<Class:#<Class:#<B:0x27932c8>>>>>> :
#<Class:Class> : #<Class:Module> : #<Class:Object> : Class : Module : Object
#<Class:#<Class:#<Class:#<Class:#<Class:#<Class:#<B:0x2792fb0>>>>>>> :
#<Class:Class> : #<Class:Module> : #<Class:Object> : Class : Module : Object
#<Class:#<Class:#<Class:#<Class:#<Class:#<Class:#<Class:#<B:0x2792c50>>>>>>>>
: #<Class:Class> : #<Class:Module> : #<Class:Object> : Class : Module :
Object
#<Class:#<Class:#<Class:#<Class:#<Class:#<Class:#<Class:#<Class:#<B:0x27928a8>>>>>>>>>
: #<Class:Class> : #<Class:Module> : #<Class:Object> : Class : Module :
Object
---
as it were i had to do this
class << self
# determine our 'singleton_super' so we can use it's ancestors
end
and this is precisely because parent/child meta classes do not fit
into the
same kind of hierarchy as their respective classes. so i will love
the new
behaviour.
i'm going to quit on this now because i feel like i've only confused
things.
sorry if i have.
I promise I will quit this too, well after this post
/Christoph