Created
May 18, 2012 22:33
-
-
Save zben/2727926 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Task | |
attr_accessor :name, :parent | |
def initialize(name) | |
@name = name | |
@parent = nil | |
end | |
def get_time_required | |
0.0 | |
end | |
end | |
class CompositeTask < Task | |
def initialize(name) | |
super(name) | |
@sub_tasks = [] | |
end | |
def add_sub_task(task) | |
@sub_tasks << task | |
task.parent = self | |
end | |
def remove_sub_task(task) | |
@sub_tasks.delete(task) | |
task.parent = nil | |
end | |
def get_time_required | |
time=0.0 | |
@sub_tasks.each {|task| time += task.get_time_required} | |
time | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment