オブジェクトが持っているメソッド一覧を出力する
def show_all_methods(o = Object) o = eval(o) if o.class == String all = [] o.methods.each do |m| begin all << o.method(m).call if m.to_s.include? "methods" rescue ArgumentError next end end all.flatten.uniq.sort end p show_all_methods ARGV.shift
使い方
コマンドラインからクラス名を指定したり、引数にクラス名を指定したりして使いましょう。
# シェルから
$ ./show_all_methods.rb String
# Rubyの中から p show_all_methods String