Sha256: c0c186b73e8894be2839b5843bcfc5b3b933e45057c476908ab1331253ebef70
Contents?: true
Size: 800 Bytes
Versions: 488
Compression:
Stored size: 800 Bytes
Contents
module AnnotatedModule 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 end
Version data entries
488 entries across 488 versions & 1 rubygems