最新版のgemパッケージのディレクトリ、RubyGems内のRubyスクリプトを列挙するスクリプト latest-gems
システムでインストールされているRubyスクリプトのリストがほしかったので、リストを得るスクリプトを書き殴ってみた。
locateやfindでリストできるけど、RubyGemsは複数のgemパッケージがインストールされている状況なので、だぶってしまうのが嫌。
機能はこんなの。
- 最新版のgemのディレクトリをリストする(latest-gems --list-dirs)
- RubyGemsで管理されているRubyスクリプト(最新版のみ)をリストする(latest-gems --list-scripts)
- それに加えて標準ライブラリ、site-rubyのRubyスクリプトもリストする(latest-gems --list-all-scripts)
俺の環境だとGem::dirが /pkgs/ruby-1.8.7/lib/ruby/gems になっているけど、実際は /usr/local/lib/ruby/gems へのシンボリックリンクになっている。
$ latest-gems --list-dirs /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4 /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/launchy-0.3.1 /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/activesupport-2.0.2 /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/flexmock-0.8.0 /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/RubyInlineAcceleration-0.0.1 ... $ latest-gems --list-scripts /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/gems.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/debug.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/command.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/const.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/http_request.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/http_response.rb ... /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/activerecord.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/httpclient-2.1.2/lib/http-access2.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/httpclient-2.1.2/lib/httpclient.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/httpclient-2.1.2/lib/http-access2/http.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/httpclient-2.1.2/lib/http-access2/cookie.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/httpclient-2.1.2/lib/httpclient/http.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/httpclient-2.1.2/lib/httpclient/cookie.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/fastercsv-1.2.1/lib/fastercsv.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/fastercsv-1.2.1/lib/faster_csv.rb $ latest-gems --list-all-scripts /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/gems.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/debug.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/command.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/const.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/http_request.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/http_response.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/rails.rb /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/init.rb ... /pkgs/ruby-1.8.7/lib/ruby/site_ruby/1.8/rwiki_/hotpage.rb /pkgs/ruby-1.8.7/lib/ruby/site_ruby/1.8/rwiki_/slide.rb /pkgs/ruby-1.8.7/lib/ruby/site_ruby/1.8/rwiki_/slide-view.rb /pkgs/ruby-1.8.7/lib/ruby/site_ruby/1.8/rwiki_/rw-like.rb /pkgs/ruby-1.8.7/lib/ruby/site_ruby/1.8/rwiki_/rw-tofu.rb /pkgs/ruby-1.8.7/lib/ruby/site_ruby/1.8/rwiki_/rw-info.rb /pkgs/ruby-1.8.7/lib/ruby/site_ruby/1.8/rwiki_/rw-arb-test.rb /pkgs/ruby-1.8.7/lib/ruby/site_ruby/1.8/rwiki_/rw-lib.rb /pkgs/ruby-1.8.7/lib/ruby/site_ruby/1.8/autotest.rb /pkgs/ruby-1.8.7/lib/ruby/site_ruby/1.8/rpa.rb
実際のコードにおけるメソッドの使われ方を探るため、まずスクリプトのリストを得る必要があった。だからスクリプトの一覧を得るスクリプト latest-gems を作成した。あとは、xargsとegrepで検索すればよい。
$ latest-gems --list-all-scripts | xargs egrep -n instance_exec /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/core_ext/object/extending.rb:32: unless defined? instance_exec # 1.9 /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/core_ext/object/extending.rb:40: # From Mauricio's http://eigenclass.org/hiki/bounded+space+instance_exec /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/core_ext/object/extending.rb:41: def instance_exec(*args, &block) /pkgs/ruby-1.8.7/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/core_ext/object/extending.rb:45: n += 1 while respond_to?(method_name = "__instance_exec#{n}") ...
http://www.rubyist.net/~rubikitch/archive/latest-gems
からもってけ!
Ruby 1.8.7、Ruby 1.9でしか動かないのであしからずw