Module: Mixiner
- Defined in:
- lib/mixiner.rb
Overview
Make easy to create mixin modules to group together related methods.
As those methods are not defined directly on the class those can be redefined afterwards.
Instance Method Summary collapse
-
#mixin(subject) ⇒ Object
Initialize or retrieve a mixin module for the given subject.
Instance Method Details
#mixin(subject) ⇒ Object
Initialize or retrieve a mixin module for the given subject
Create a mixin module to group a set of related methods making sure that ‘define_method` is public so it is easier to add methods there.
The module is defined just once and is included in the base class to make those methods accessible.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mixiner.rb', line 44 def mixin subject if self.const_defined? subject, false self.const_get subject else mod = Module.new do public_class_method :define_method end self.const_set subject, mod self.include mod mod end end |