FrontPage
New
Tools
Index
TempPage
Edit: Ruby で定数を表示する
8< def print_constants_recursive( module_obj ) ## インデント量 indent = " " * (((caller( 0 ).size) + 1) / 3) ## モジュールの前置記号ハッシュ preffix_hash = { true => "*", false => "" } ## モジュールの定数毎に処理 module_obj.constants.sort.each{|one_str| ## 文字列からそのオブジェに変換 one_obj = module_obj.module_eval( one_str ) ## 表示 print indent, preffix_hash[one_obj.is_a?( Module )] print "#{one_str} = #{one_obj.inspect}\n" ## モジュールなら再帰 if one_obj.is_a?( Module ) print_constants_recursive one_obj end } end def print_constants_all( obj ) ## インデント量 indent = " " * (caller( 0 ).size - 2) ## 表示 print indent, "*", obj.inspect, "\n" print_constants_recursive( obj ) if obj.is_a?( Module ) end print_constants_all( Errno ) >8
Attachment
New: