From: Sam Stephenson Date: 2004-11-29T08:26:46+09:00 Subject: Re: private include On Mon, 29 Nov 2004 07:56:27 +0900, trans. (T. Onoma) wrote: > Is there a simple way to include a module such that all the included methods > are private? If you can change the module definition itself, just add ``private'' before defining any methods. If not, perhaps this would work: | class Module | def privately_include(mod) | self.class_eval {include(mod)} | mod.instance_methods.each do |m| | self.class_eval {private m.to_sym} | end | nil | end | end An example: | irb(main):001:0> module Foo; def bar() end end | => nil | irb(main):002:0> class Baz; privately_include Foo end | => nil | irb(main):003:0> Baz.new.bar | NoMethodError: private method `bar' called for # | from (irb):3 Note that this won't make future public methods defined in the module private in the including class. > Thanks, > T. Sam