Rake as a library/API: possible?

Hi all,
I'm trying to use rake as a library/API to retrieve the rake tasks in a given directory.

Basically I'm looking to mimic the output of
  rake --tasks --silent

Looking through the source code and trying out some stuff in irb I'm getting the impression this usage was not considered at design stage. But is it possible?

a = Rake::Application.new

=> #<Rake::Application:0x4e4c8...

a.init

...throws me out of IRB, as does "Rake::Application.new.run"

I've been trying for a good while to get around the above all to no avail.

Can this be done? Am I better off by just doing:
  tasks = x%{rake --tasks --silent}

Thanks!
David

I think the biggie is that Rake::Application is a singleton.

% ruby -rubygems -e 'require "rake"; load "Rakefile"; p Rake.application.tasks.map { |t| t.name }.sort'
["announce", "audit", "autotest", "check_extra_deps", "check_manifest", "clean", "clobber", "clobber_docs", "clobber_package", "clobber_rcov", "config_hoe", "debug_gem", "default", "deps:email", "deps:fetch", "deps:list", "doc", "doc/index.html", "docs", "email", "flay", "flog", "gem", "generate_key", "install_gem", "multi", "package", "pkg", "pkg/ZenTest-4.0.0", "pkg/ZenTest-4.0.0.gem", "pkg/ZenTest-4.0.0.tgz", "post_blog", "post_news", "publish_docs", "publish_on_announce", "rcov", "rcov_info", "rcov_overlay", "redocs", "release", "repackage", "ridocs", "sort", "test", "test_deps", "update"]

···

On May 13, 2009, at 04:11 , David Palm wrote:

Looking through the source code and trying out some stuff in irb I'm getting the impression this usage was not considered at design stage. But is it possible?

a = Rake::Application.new

=> #<Rake::Application:0x4e4c8...

a.init

...throws me out of IRB, as does "Rake::Application.new.run"