Class: Object

Inherits:
BasicObject
Defined in:
lib/including.rb

Instance Method Summary collapse

Instance Method Details

#including(mixin, options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/including.rb', line 2

def including(mixin, options = {})
  include mixin and return unless options[:only] || options[:except]
  included_module = mixin.dup

  excluded_methods = (
    options[:except] ||
    included_module.instance_methods(false) - options[:only]
  ).map(&:to_sym)

  (include included_module).tap do
    excluded_methods.each do |meth|
      included_module.send(:undef_method, meth)
    end
  end
end