Sha256: 04fb222b2298c0d1bcac74410a6925d14e8b6072e8010ed7100116aae9bdb400
Contents?: true
Size: 675 Bytes
Versions: 2
Compression:
Stored size: 675 Bytes
Contents
class ImportError < Exception; end module Kernel # abstraction:: only include the methods given by _meths_ # implementation:: includes a duplicate of _mod_ with all uneeded instance methods removed def import(mod, *meths) mod_dup = mod.dup unless meths.empty? # get list of methods to remove module ims = mod.instance_methods.map {|m| m.to_sym} removes = ims - meths if removes.size != (ims.size - meths.size) raise ImportError, "##{(meths - ims).join(' and #')} not found in #{mod}" end mod_dup.module_eval do removes.each { |meth| remove_method meth } end end include mod_dup end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
module-import-0.3.0 | lib/module-import.rb |
module-import-0.2.2 | lib/import.rb |