From: "(Dezawa Shin-ichiro)" (Dezawa Shin-ichiro) Date: 1997-02-04T23:23:47+09:00 Subject: [ruby-list:2052] Methods.htm ºîÀ® tool ----Next_Part(Tue_Feb__4_23:18:17_1997)-- Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit 出沢ã§ã™ 「module ã®é–¢æ•°ã‚‚å–り込ã¿å‡ºã—ãŸã‚“ã§ã€private ã‚‚å–り扱ã†ç”¨ã« ãªã£ãŸã‚“ã§ã™ã­ã€ã€ã£ã¦ã„ã‚れã¦ã¯ã¦ã€ã€ã€ã¨æ€ã£ã¦ãŸã‚“ã§ã™ãŒã€ ã¿ã¦ã¿ãŸã‚‰ rb_define_module_function ã§ã—ãŸã€‚ ãŸã—㋠組ã¿è¾¼ã¿ class ã«includeã•れã¦ã„ã‚‹ enum 㨠compare ã«ã¯ ç„¡ã‹ã£ãŸå®šç¾©ã ã¨èª¿ã¹ãŸæ°—ã¯ã™ã‚‹ãŒã€ã€ã€ ã‚ã™ã‚ŒãŸã€‚ ----Next_Part(Tue_Feb__4_23:18:17_1997)-- Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit #!/usr/local/bin/ruby # メソッド㮠ovwerideãŒã‚ã£ãŸã¨ãã€ã™ã¹ã¦ã® super ã® LIST を作る # クラスå 㯠最後ã«å®šç¾©ã—ãŸã‚‚ã®ã€‚ link ã¯ãƒžãƒ‹ãƒ¥ã‚¢ãƒ«ã«ã‚ã‚‹ã‚‚ã®ã«å¼µã‚‹ã€‚ # cArray = rb_define_class("Array", cObject); # rb_include_module(cArray, mEnumerable); # # rb_define_singleton_method(cArray, "new", ary_s_new, -1); # rb_define_singleton_method(cArray, "[]", ary_s_create, -1); # rb_define_method(cArray, "to_s", ary_to_s, 0); # rb_define_method(cArray, "inspect", ary_inspect, 0); require "getopts" getopts( "i" ) # Index # grobals $ManDir="/usr/man/html/ruby-man/man/" # dir of *.html $Anker = Hash.new # anker-list from $ManDir/*.html # key = method name(String) "plus", "class.grob" ,, # value= [ [class-name,anker], [ ], [ ],,,] $CLASS=Hash.new # classID => object of CLS # print format $tail=["%s | ","%s\n"] $format0="%s%s" $format1="%s" $RenamMethod={ # method name rewrite rule "%" =>"mod", "&" =>"and", "<" =>"gt", "<=" =>"ge", "<<" =>"lshift", "**"=>"pow", "|" =>"or", ">" =>"lt", ">=" =>"le", ">>"=>"rshift", "/" =>"div", "^" =>"xor", "==" =>"equal","<=>"=>"cmp", "[]" =>"aref", "+" =>"plus", "~" =>"inv", "==="=>"eqq", "=~" =>"match","[]="=>"aset", "-" =>"minus","+@"=>"uplus","-@" =>"uminus", "*" =>"mul", "times" =>"mul" } def rename(methodName) # Rename special method href = methodName.dup href = $RenamMethod[href] if $RenamMethod[href] href.sub(/\?$/,"_p").sub(/!$/,"_bang") end ################# class define ###### class CLS # propaty # @classtype(Str) "class", "module", "boot", or nil # @name(Str) @super(Str or nil) # @modules(Ary) classID of included module # @method(Hash) Key:method-name(Str) Value:class-name(Str) # @classmethod(Hash) same as @method. Key:method-name without class-name # @methods # @classmethods(Hash) # all methods from methoclass, module, super, super-super # Key:method-name(Str) Value: Array of class-name(Str) # @supers(Ary) Array of classID as [super, super-super,super-super,,,,] # def setclass(name,superClass=nil,classtype=nil) @name=name ; @super = superClass ; @classtype = classtype end def classtype @classtype end def name @name end def setModule(incModule) if @modules @modules.push(incModule) else @modules=Array[incModule] end end def modules @modules end def setMethod(method) # allMethod ã«ã‚ˆã‚Šã€å­ä¾›ã«å–り込ã¾ã‚Œã‚‹ãŸã‚ã€ã©ã®ã‚¯ãƒ©ã‚¹ã‹ã‚‰ã® # method ã‹ã‚’明確ã«ã™ã‚‹ãŸã‚ã€å€¤ã¨ã—㦠クラスå(Str)ã‚’æŒãŸã›ã‚‹ if @method @method[method]=[@name] else @method={method=>[@name]} end end def setClassMethod(method) if @classmethod @classmethod[method]=[@name] else @classmethod={method=>[@name]} end end def getMethod @method end def addHash(a,b) if a c = a.dup if b b.each{|k,v| if c[k] == nil c[k]=v else c[k]+= v end } end end c end def allClassMethod unless @classmethods if @classmethod @classmethods=@classmethod.dup else @classmethods=Hash.new end end if $CLASS[@super] @classmethods=addHash(@classmethods,$CLASS[@super].allClassMethod) end @classmethods end def allMethod unless @methods if @method @methods=@method.dup else @methods=Hash.new end if @modules && @modules.size > 0 @modules.each{ |modul| if $CLASS[modul] @methods=addHash(@methods, $CLASS[modul].allMethod) end } end if $CLASS[@super] @methods=addHash(@methods,$CLASS[@super].allMethod) end end @methods end def allSuper unless @supers # @super is classID, @supers is Array of String @supers=Array.new if $CLASS[@super] @supers << [$CLASS[@super].name] @supers += $CLASS[@super].allSuper end end @supers end ########### print out method ########## def printHREFforClass if allSuper.size>0 @supersList = " < " + @supers.join(" < ") else @supersList = "" end printf(" %s%s\n", @name,@name,@supersList) end def printClassHeader printf("

%s%s
\n\n", @name,@name,@name,@supersList) end def printClassMethod allClassMethod # @classmethods(Hash) made if @classmethods.size>0 @right=0 # 0: left column, 1: right column print "\n" @classmethods.keys.sort.each{|methodName| printMethodHref(methodName,@classmethods[methodName]) } end end def printMethod allMethod # @methods(Hash) made if @methods.size>0 @right=0 # 0: left column, 1: right column print "\n" @methods.keys.sort.each{|methodName| printMethodHref(methodName,@methods[methodName]) } end end def rename(methodName) # Rename special method href = methodName.dup href = $RenamMethod[href] if $RenamMethod[href] href.sub(/\?$/,"_p").sub(/!$/,"_bang") end def printMethodHref(methodName,classNameAry) # classNameAry is ã“㮠メソッドãŒå®šç¾©ã•れã¦ã‚‹ã‚¯ãƒ©ã‚¹ã® Array href=rename(methodName) # example # methodName "+", "sub", "class.grob" # --> href "plus","sub", "class.grob" method = methodName.dup method.sub!(/class\./,"") hrefClass = nil #ã“㮠メソッドã«ã¤ã„ã¦ã® NAME= ãŒã‚ã£ãŸ[classname,anker tag] classNameAry.each{ |cls| if $Anker[href] && # $Anker[href] is Array of [classname,anker tag] hrefClass = $Anker[href].assoc(cls) # cls.html ã« NAME="href" ãŒã‚ã‚‹å ´åˆ break end } # # or if hrefClass printf($format0,hrefClass[1],method) else printf($format1,method) end # class list Fixint < Num < ,,,,, printf($tail[@right],classNameAry.join("<")) @right = 1 - @right end end # of class define ################################################################### ################################## # 準備 man ã«ã‚るアンカー ã®ãƒªã‚¹ãƒˆã‚¢ãƒƒãƒ— # ruby-man/*.html ã‹ã‚‰ アンカー を抜ãå–ã‚‹ Dir.glob($ManDir + "*.html").each{ |manfile| manFile = open(manfile) manfile.sub!(/.*\//,"") classname = manfile.sub(/\.html/,"") while manFile.gets if $_ =~ //i anker="" href = $1.sub(/^[^.]*\./,"class.") # if class method: Dir.grob --> class.grob $Anker[href]=Array.new unless $Anker[href] $Anker[href] << [classname,anker] end end manFile.close } #exit ##################################################################### while line = gets next if ["class.c","eval.c"].include?(ARGF.filename) token=line.strip.split(/[\s(),";]+/) # cKernel = boot_defclass("kernel", 0); if token[2] == "boot_defclass" token[3] = "Kernel" if token[3] == "kernel" $CLASS[token[0]]= CLS.new unless $CLASS[token[0]] $CLASS[token[0]].setclass(token[3],token[4],"boot") #cArray = rb_define_class("Array", cObject); elsif token[2] == "rb_define_class" && token[3] != "Data" && token[3] != "nil" && token[3] != "true" && token[3] != "false" && token[0] !~ /^e/ #rint token[3] = "MatchData" if token[3] == "MatchingData" $CLASS[token[0]]= CLS.new unless $CLASS[token[0]] $CLASS[token[0]].setclass(token[3],token[4],"class") # module # included into class # "Enumerable" "Comparable" # Enum Compar # NOT included standalone module # "Errno" "FileTest" "GC" "ObjectSpace" "Math" "Process" # FileTest GC ObSpace Math Process # mEnumerable = rb_define_module("Enumerable"); elsif token[2] == "rb_define_module" mdl = "standModule" { token[3] = "Enum" , mdl="incModule" } if token[3] == "Enumerable" { token[3] = "Compar", mdl="incModule" } if token[3] == "Comparable" token[3] = "ObSpace" if token[3] == "ObjectSpace" $CLASS[token[0]]= CLS.new unless $CLASS[token[0]] $CLASS[token[0]].setclass(token[3],nil,mdl) # rb_define_module_function(mProcess, "uid", proc_getuid, 0); elsif token[0] == "rb_define_module_function" $CLASS[token[1]]= CLS.new(token[1]) unless $CLASS[token[1]] $CLASS[token[1]].setMethod(token[2]) # rb_include_module(cArray, mEnumerable); elsif token[0] == "rb_include_module" token[2] = "Enum" if token[2] == "Enumerable" token[2] = "Compar" if token[2] == "Comparable" $CLASS[token[1]]= CLS.new(token[1]) unless $CLASS[token[1]] $CLASS[token[1]].setModule(token[2]) # rb_define_singleton_method(cArray, "new", ary_s_new, -1); # rb_define_method(cArray, "to_s", ary_to_s, 0); elsif token[1] != "TopSelf" && token[1] != "cNil" && token[1] != "cTrue" && token[1] != "cFalse" && token[1] != "cData" if token[0] == "rb_define_method" $CLASS[token[1]]= CLS.new(token[1]) unless $CLASS[token[1]] $CLASS[token[1]].setMethod(token[2]) elsif token[0] == "rb_define_singleton_method" $CLASS[token[1]]= CLS.new(token[1]) unless $CLASS[token[1]] $CLASS[token[1]].setClassMethod("class." + token[2]) end end end # of while for source gets ############ OUT PUT ######################## ############ OUT PUT Index ######################## if $OPT_i ## header ## print " 組ã¿è¾¼ã¿ã‚¯ãƒ©ã‚¹ã® method Index

組ã¿è¾¼ã¿ã‚¯ãƒ©ã‚¹ã® method Index

" # get all methods from all class classMethods = Hash.new methods = Hash.new $CLASS.keys.compact.each{ |classID| next unless ["class","standModule"].include?( $CLASS[ classID ].classtype ) $CLASS[ classID ].allMethod.each{|mthd,classNameAry| methods[mthd] |= classNameAry if methods[mthd] methods[mthd] = classNameAry unless methods[mthd] } $CLASS[ classID ].allClassMethod.each{|mthd,classNameAry| classMethods[mthd] |= classNameAry if methods[mthd] classMethods[mthd] = classNameAry unless methods[mthd] } } # output class method print "
クラスメソッド
メソッド
hashhash
\n\n" classMethods.keys.sort.each{|methodName| href=rename(methodName) method = methodName.dup method.sub!(/class\./,"") printf("",hrefClass[1],cls) else printf("",cls) end } print "\n" } # output method print "\n\n" methods.keys.sort.each{|methodName| href=rename(methodName) method = methodName.dup printf("",hrefClass[1],cls) else printf("",cls) end } print "\n" } print "
クラスメソッド
%s",method) classMethods[methodName].compact.sort.each{|cls| if $Anker[href] && # $Anker[href] is Array of [classname,anker tag] hrefClass = $Anker[href].assoc(cls) printf("%s%s%s
メソッド
%s",method) methods[methodName].compact.sort.each{|cls| if $Anker[href] && # $Anker[href] is Array of [classname,anker tag] hrefClass = $Anker[href].assoc(cls) printf("%s%s%s
\n" else ############ OUT PUT Methods ######################## ## header ## print " 組ã¿è¾¼ã¿ã‚¯ãƒ©ã‚¹ã® method

組ã¿è¾¼ã¿ã‚¯ãƒ©ã‚¹ã® method

" ## HREF for Classes ## print "\n" $CLASS.keys.compact.sort.each{ |classID| next if $CLASS[ classID ].classtype != "class" $CLASS[ classID ].printHREFforClass } print "\n" $CLASS.keys.compact.sort.each{ |classID| next if $CLASS[ classID ].classtype != "standModule" $CLASS[ classID ].printHREFforClass } print "
モジュール

\n" ## Print HREF for method of all classes ## $CLASS.keys.compact.sort.each{ |classID| next if $CLASS[ classID ].classtype != "class" $CLASS[ classID ].printClassHeader $CLASS[ classID ].printClassMethod $CLASS[ classID ].printMethod print "\n" } $CLASS.keys.compact.sort.each{ |classID| next if $CLASS[ classID ].classtype != "standModule" $CLASS[ classID ].printClassHeader $CLASS[ classID ].printClassMethod $CLASS[ classID ].printMethod print "\n" } end ----Next_Part(Tue_Feb__4_23:18:17_1997)----