class Module
Public Instance Methods
append_from( module_to_append_from, *methods_to_keep )
click to toggle source
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.
# File lib/cem/ccommon.rb, line 54 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