Class: Module
- Inherits:
-
Object
- Object
- Module
- Defined in:
- lib/cem/ccommon.rb
Instance Method Summary collapse
-
#append_from(module_to_append_from, *methods_to_keep) ⇒ Object
Append only the given methods from the given mod(ule) Adapted from: www.ruby-forum.com/t/partial-append-features/66728/12 Why? Enumerable has too many methods to include at once.
Instance Method Details
#append_from(module_to_append_from, *methods_to_keep) ⇒ Object
Append only the given methods from the given mod(ule) Adapted from: www.ruby-forum.com/t/partial-append-features/66728/12 Why? Enumerable has too many methods to include at once.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cem/ccommon.rb', line 64 def append_from( module_to_append_from, *methods_to_keep ) methods_to_keep.map! { |m| m.to_sym } methods_to_remove = module_to_append_from.instance_methods(false) - methods_to_keep new_mod = Module.new new_mod.module_eval do include module_to_append_from methods_to_remove.each { |meth| undef_method meth } end # Sanity check: check = methods_to_keep - new_mod.instance_methods(true) raise "The following methods are not in the given module: #{check.inspect}" if !check.empty? include new_mod end |