From: Gavin Kistner Date: 2005-08-20T00:10:26+09:00 Subject: Re: Controlling acces to object instantiation? --Apple-Mail-1-128133013 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Aug 19, 2005, at 9:03 AM, Andrew S. Townley wrote: > The main issue here is that I want to prevent the client code from > instantiating their own objects. The objects should be created > only by > a factory of some sort (who has implementation-specific configuration > information about how to bootstrap them). class Foo def self.make self.new( rand ) end def initialize( id ) @id = id end class << self protected :new end end p f1 = Foo.make # => # p f2 = Foo.new( 12 ) # => /Users/gkistner/Desktop/tmp.rb:16: protected method `new' called for Foo:Class (NoMethodError) --Apple-Mail-1-128133013--