From: Jeremy Date: 2003-03-26T11:05:44+09:00 Subject: Conditionally make a method private? 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: class Hider def initialize(val) private_class_method :method1 if val private_class_method :method2 if not val end def method1 #... end def method2 #... end end ahider = Hider.new(true) This spits back out to me: 3:in `initialize': undefined method `private_class_method' for # (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. I've tried putting the private_class_method in other seperate methods, I've tried just using "private :method2" and the like, but they all give me a similar response. I'm guessing that private and private_class_method can't be inside of other methods. Is conditional hiding of methods like I want to do even possible? Any insight is appreciated, Jeremy