On Tue, 2003-03-25 at 21:05, Jeremy wrote:
> Hello again!
> 
> I've googled this one, as well as looking in Pickaxe and Ruby Way, and I
> can't seem to find out anything about this.  What I want to do is create a
> class that, when instanced, depending on the argument given to .new, hides
> some methods or others.  For example:
> ahider = Hider.new(true)
> 
> This spits back out to me:
> 
> 3:in `initialize': undefined method `private_class_method' for
> #<Hider:0x401c157c> (NameError)
>         from test.rb:16:in `new'
>         from test.rb:16
> 
> What I want to happen is when I issue "Hider.new(true)", I want it to make
> it so that method1 is private.  Likewise, when I do "Hider.new(false)", I
> want it to make method2 private.

Would a Factory pattern work better in this case? I.e. have a base
class, then derive the two different classes from that. Use a Factory to
give you the instance you ask for. If you call
Factory.instance(SOME_NAME) would return a SomeName instance, whereas
Factory.instance(SOME_OTHER_NAME) would return a SomeOtherName instance.
SomeName and SomeOtherName would both be subclasses of BaseClass.

Regards,
  JJ