Method: Module#-
- Defined in:
- lib/core/facets/module/op.rb
#-(other) ⇒ Object
Subtract modules.
module AMinus
def a; "a"; end
def b; "b"; end
end
CMinus = AMinus - [:a]
class XMinus; include CMinus; end
expect NameError do
XMinus.new.a #=> "a"
end
XMinus.new.b #=> "b"
TODO: Should this use all instance methods, not just public?
CREDIT: Thomas Sawyer, Robert Dober
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/core/facets/module/op.rb', line 64 def -(other) instance_methods = instance_methods(true).map{|m| m.to_sym} case other when Array subtract = instance_methods & other.map{|m| m.to_sym} when Module subtract = instance_methods & other.instance_methods(true).map{|m| m.to_sym} # false? when String, Symbol subtract = instance_methods & [other.to_sym] end base = self Module.new do include base subtract.each{ |x| undef_method x } end end |