# SOS Taskable

**URL:** <https://www.ruby-forum.com/t/sos-taskable/65604>\
**Category:** Ruby\
**Created:** [August 19, 2006, 6:21pm UTC](https://www.ruby-forum.com/t/sos-taskable/65604 "2006-08-19T18:21:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [August 19, 2006, 6:21pm UTC](https://www.ruby-forum.com/t/sos-taskable/65604/1 "2006-08-19T18:21:11Z")

</div>

I’m stuck. I can’t figure out how to implement Taskable. If you haven;t  
seen my rantings abut this before, Taskable is an emulation of Rake’s  
task syntax:

desc “this and that”

task ‘foo’ =\> [‘bar’] do  
…  
end

but limted to the scope of a module/class. Also, tasks themselves are  
just be regular methods.

It’s easy enough to define:

class Module  
def task( name\_preqs, &action )  
if Hash === name\_preqs  
name = name\_preqs.key  
preqs = name\_preqs.value  
else  
name = name\_preqs  
preqs = []  
end  
define\_method( name ) do |\*args|  
preqs.each { |n| send(n,\*args) }  
action.call(\*args)  
end  
end  
end

The challenge comes from keeping track of the prequistes so they won’t  
get run more than once. With some help on this list I came to  
understand that I needed to use TSort, that much seemed to work. But  
problems arise in just looking up the tasks. Consider when a module  
extends itself, then a task is called at the module level, how will it  
look up a prerequiste that was defined at the instance level?

Anyway, the whole idea was to create a system that parallels Method,  
UnboundMethod, instance\_method, instance\_methods, etc., but substitute  
‘task’ for ‘method’. Maybe this is just too low level to be pulled off  
in pure Ruby? I’m on the verge of giving up --I’m weary of working on  
it. Butmaybe someone else can see a clear soltuion?

Thanks,  
T.

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [August 19, 2006, 9:51pm UTC](https://www.ruby-forum.com/t/sos-taskable/65604/2 "2006-08-19T21:51:32Z")

</div>

Trans wrote:

> I’m stuck. I can’t figure out how to implement Taskable.

Never mind. I just reworote the whole thing from scratch WITHOUT using  
TSort and got it to work.

T.
