Permalink
Browse files

Methods should be private

For the same reasons `puts` is private: it makes no use of `self` and it
doesn't make sense to call with an explicit reciever (e.g. `self.puts` or
`Object.puts` wouldn't make sense).
  • Loading branch information...
1 parent 9776611 commit c6a39087a154885a20392b05dc1ee406c72efca9 @misfo misfo committed May 7, 2012
Showing with 8 additions and 3 deletions.
  1. +1 −0 lib/rns.rb
  2. +7 −3 spec/rns/rns_spec.rb
View
@@ -57,6 +57,7 @@ def add_methods(to, use_spec)
to.send(:define_method, name) do |*args|
from.method(name).call(*args)
end
+ to.send(:private, name)
end
end
end
View
@@ -24,8 +24,8 @@ class Thing
extend Rns.module_with(Math::Arithmetic => [:inc])
include Rns.module_with(Math::Statistics => [:avg])
- def inced_one
- self.class.inc 1
+ def self.inced_one
+ inc 1
end
def average
@@ -69,7 +69,11 @@ def average
end
it "works with private module methods" do
- Thing.new.inced_one.should == 2
+ Thing.inced_one.should == 2
+ end
+
+ it "should add methods privately" do
+ lambda { Thing.new.avg [11, 42, 7] }.should raise_error(NoMethodError)
end
end

0 comments on commit c6a3908

Please sign in to comment.