けいじゅ@日本ラショナルソフトウェアです.

In [ruby-dev :01370 ] the message: "[ruby-dev:1370] Re: [MethodIndex]
Bug and question ", on Feb/03 13:42(JST) 石塚圭樹 writes:

とりあえず, [ruby-dev: 01370] のclass_ancestorsを用いて実装し始めまし
たが, バグと問題点がありました.

1. SEGV

[ruby-dev: 01370] のclass_ancestorsはmoduleでも適用できますので, 以下
のように定義し直しました.

class Module
  def module_ancestors
    # all = [[class1, mod1-ancestors, mod2-anectors], ... ]
    m_sets = {}
    a_serials = Class.ancestors.reverse.collect{|a| 
      if a.instance_of?(Module)
	m_sets[a] = a
      end
      [a]
    }
    for cls in ancestors.find_all{|m| ! m.instance_of?(Module)}.reverse
      ancs = [cls]
      for e in eval("class << cls; included_modules; end")
	for a in e.ancestors
	  if !m_sets.include?(a)
	    ancs.push a
	    m_sets[a] = cls
	  end
	end
      end
      a_serials.push ancs
    end
    a_serials.reverse!
  end
end

すると,

module Foo; end
Foo.module_ancestors

でSEGVします(;_;

2. Object#singleton_methods

rbc0> class Foo;end
rbc0> def Foo.fo;end
rbc0> Foo.singleton_methods
["fo"]
rbc0> class Bar < Foo; end
rbc0> Bar.singleton_methods
["fo"]

となります. 一見正しいように感じるのですが, 

rbc0> Class.instance_methods(TRUE)
["new", "superclass", "const_get", "undef_method", "===", "public_class_method", "ancestors", "constants", ">=", "remove_method", "<=", "method_defined?", "const_defined?", "name", "<", "private_instance_methods", "module_eval", "clone", ">", "const_set", "included_modules", "alias_method", "instance_methods", "to_s", "private_class_method", "<=>", "private_methods", "is_a?", "=~", "methods", "instance_eval", "instance_of?", "hash", "instance_variables", "respond_to?", "dup", "singleton_methods", "type", "equal?", "kind_of?", "extend", "inspect", "id", "send", "==", "nil?", "remove_instance_variable", "to_a", "eql?"]

が追加されているべきではないでしょうか??

__
................................石塚 圭樹@日本ラショナルソフトェア...
----------------------------------->> e-mail: keiju / rational.com <<---