3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/rbbt/workflow/annotate.rb', line 3
def self.add_consummable_annotation(target, *annotations)
if annotations.length == 1 and Hash === annotations.first
annotations.first.each do |annotation, default|
target.send(:attr_accessor, annotation)
target.send(:define_method, "consume_#{annotation}") do
value = instance_variable_get("@#{annotation}") || default.dup
instance_variable_set("@#{annotation}", default.dup)
value
end
end
else
annotations.each do |annotation|
target.send(:attr_accessor, annotation)
target.send(:define_method, "consume_#{annotation}") do
value = instance_variable_get("@#{annotation}")
instance_variable_set("@#{annotation}", nil)
end
end
end
end
|