Skip to content

Instantly share code, notes, and snippets.

@zben
Created May 18, 2012 22:33
Show Gist options
  • Save zben/2727926 to your computer and use it in GitHub Desktop.
Save zben/2727926 to your computer and use it in GitHub Desktop.
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