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

Version Path
rbbt-util-6.0.3 lib/rbbt/workflow/annotate.rb
rbbt-util-5.44.1 lib/rbbt/workflow/annotate.rb
rbbt-util-5.43.0 lib/rbbt/workflow/annotate.rb
rbbt-util-5.42.0 lib/rbbt/workflow/annotate.rb
rbbt-util-5.41.1 lib/rbbt/workflow/annotate.rb
rbbt-util-5.41.0 lib/rbbt/workflow/annotate.rb
rbbt-util-5.40.5 lib/rbbt/workflow/annotate.rb
rbbt-util-5.40.4 lib/rbbt/workflow/annotate.rb
rbbt-util-5.40.3 lib/rbbt/workflow/annotate.rb
rbbt-util-5.40.0 lib/rbbt/workflow/annotate.rb
rbbt-util-5.39.0 lib/rbbt/workflow/annotate.rb
rbbt-util-5.38.1 lib/rbbt/workflow/annotate.rb
rbbt-util-5.38.0 lib/rbbt/workflow/annotate.rb
rbbt-util-5.37.16 lib/rbbt/workflow/annotate.rb
rbbt-util-5.37.15 lib/rbbt/workflow/annotate.rb
rbbt-util-5.37.14 lib/rbbt/workflow/annotate.rb
rbbt-util-5.37.13 lib/rbbt/workflow/annotate.rb
rbbt-util-5.37.12 lib/rbbt/workflow/annotate.rb
rbbt-util-5.37.11 lib/rbbt/workflow/annotate.rb
rbbt-util-5.37.10 lib/rbbt/workflow/annotate.rb