Module: Doodle::Embrace
- Defined in:
- lib/doodle.rb
Overview
embrace
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
Instance Method Summary collapse
-
#embrace(other, &block) ⇒ Object
fake module inheritance chain.
Instance Method Details
#embrace(other, &block) ⇒ Object
fake module inheritance chain
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# 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 |