# Rake as a library/API: possible?

**URL:** <https://www.ruby-forum.com/t/rake-as-a-library-api-possible/167866>\
**Category:** Ruby\
**Created:** [May 13, 2009, 1:12pm UTC](https://www.ruby-forum.com/t/rake-as-a-library-api-possible/167866 "2009-05-13T13:12:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [May 13, 2009, 1:12pm UTC](https://www.ruby-forum.com/t/rake-as-a-library-api-possible/167866/1 "2009-05-13T13:12:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [May 13, 2009, 9:25pm UTC](https://www.ruby-forum.com/t/rake-as-a-library-api-possible/167866/2 "2009-05-13T21:25:14Z")

</div>

On May 13, 2009, at 04:11 , David P. 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”

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”]
