Sha256: 8d7daec9737d16f0de5c84d870d94f58e41ad2d6c19f29ca4f41d32c89c5b630
Contents?: true
Size: 793 Bytes
Versions: 2
Compression:
Stored size: 793 Bytes
Contents
module MetaExtension def self.extended(base) meta = class << base; self; end base.class_variable_set("@@extension_attrs", []) meta.define_method(:extension_attr) do |*attrs| self.class_variable_get("@@extension_attrs").concat attrs attrs.each do |a| self.attr_accessor a end end meta.define_method(:setup) do |obj,*rest| obj.extend base self.class_variable_get("@@extension_attrs").zip(rest).each do |name,value| obj.instance_variable_set("@#{name}", value) end obj end base.define_method(:annotate) do |other| attr_values = meta.class_variable_get("@@extension_attrs").collect do |a| self.instance_variable_get("@#{a}") end base.setup(other, *attr_values) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
scout-gear-1.1.1 | lib/scout/meta_extension.rb |
scout-gear-1.1.0 | lib/scout/meta_extension.rb |