the intent of embrace is to provide a way to create directives that affect all members of a class ‘family’ without having to modify Module, Class or Object - in some ways, it’s similar to Ara Howard’s mixable though not as tidy :S
this works down to third level class << self - in practice, this is perfectly good - it would be great to have a completely general solution but I’m doubt whether the payoff is worth the effort
fake module inheritance chain
# File lib/doodle.rb, line 260 def embrace(other, &block) # include in instance method chain include other sc = class << self; self; end sc.module_eval { # class method chain include other # singleton method chain extend other # ensure that subclasses are also embraced define_method :inherited do |klass| #p [:embrace, :inherited, klass] klass.__send__(:embrace, other) # n.b. closure klass.__send__(:include, Factory) # is there another way to do this? i.e. not in embrace #super(klass) if defined?(super) end } sc.module_eval(&block) if block_given? end
Disabled; run with $DEBUG to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.