banister / object2module

Convert Classes and Objects to Modules so they can be extended/included.
MIT License
9 stars 0 forks source link

gen_include doesn't respect singleton classes #4

Closed jeremyevans closed 13 years ago

jeremyevans commented 13 years ago

class A; def self.a() [1] end end class B < A; def self.a() [2] + super() end end class C < B; def self.a() [3] + super() end end class D < A; def self.a() [4] + super() end; gen_include C end p D.a => [4, 1]

Should be [4, 3, 2, 1]

banister commented 13 years ago

hehehehe, wow you really went to town :)

Object2module converts classes into modules - and module inclusion does not bring in the singleton class. So this behavior is part of the spec. Note I call it gen_include not 'multi_inherit`.

The behavior is consistent with pure modules:

module A
  def self.a
  end
end

module B
  include A

  a #=> NoMethodError
end
jeremyevans commented 13 years ago

Fair enough. It's just that you described it as real multiple inheritance in the evilr ticket, which should act like classes, not modules.

banister commented 13 years ago

Sorry if i described it that way :( yeah it just makes classes/objects work like modules, i guess i should have made that clearer.

Your other issue (aside from the rb_is_meta_singleton issue) is very interesting, im looking at it now. I have a feeling it could be similar to this behaviour (which is part of the ruby spec:

class A; end
module M; end
class B < A; include M; end
class A; include M; end

B.ancestors #=> [B, M, A, M]

But, actually, i think i'm wrong since in your code the As end up being adjacent. It's confusing because the test for double inclusion is against the method tables, so I would not expect this issue to arise. Nonetheless, i guess i'll step through the code in gdb to figure out what's going on,

cheers