Projects

Ticket #61 (closed defect: fixed)

Opened 4 years ago

Last modified 3 years ago

ObjectSpace.each_object(Foo) doesn't yield subclasses

Reported by: kreatix@… Owned by: lsansonetti@…
Priority: blocker Milestone: MacRuby 0.2
Component: MacRuby Keywords:
Cc:

Description

Runing this code:

a = []; ObjectSpace.each_object(Module) { |c| a << c.class }; p a.uniq

on MRI:

# => [Module, Class]

On Macruby:

# => [Module]

Change History

Changed 4 years ago by lsansonetti@…

  • status changed from new to closed
  • resolution set to fixed
  • milestone set to MacRuby 0.2

Our implementation of ObjectSpace.each_object yields subclasses, except in one very special case, when the parameter is Class or Module. This is fixed in r218.

$ ./miniruby -e "p ObjectSpace.each_object(Class).map { |x| x.class }.uniq"
[Class]
$ ./miniruby -e "p ObjectSpace.each_object(Module).map { |x| x.class }.uniq"
[Class, Module]

Changed 3 years ago by kreatix@…

This seems to be broken again.

>> ObjectSpace.each_object(Module).map { |x| x.class }.uniq
=> [Module]
>> ObjectSpace.each_object(Class).map { |x| x.class }.uniq
=> [Class, Module]
>> ObjectSpace.each_object(Class).include? NSObject
=> false
>> NSObject.is_a? Class
=> true

on MRI 1.9:

>> ObjectSpace.each_object(Module).map { |x| x.class }.uniq
=> [Module, Class]
>> ObjectSpace.each_object(Class).map { |x| x.class }.uniq
=> [Class]

PS. I tried to reopen the ticket, but got "Warning: No permission to change ticket fields." Perhaps I should create a new one?

Note: See TracTickets for help on using tickets.