From: Curt Sampson Date: 2002-04-26T16:33:49+09:00 Subject: Re: appending methods to class inside module On Fri, 26 Apr 2002, Ian Macdonald wrote: > This runs fine. However, the only thing that should be able to access > the new String#check method are objects of Class Bar. You want to do something along the lines of "friend" in C++, but Ruby doesn't appear to have this capability. A method's access permission is the same for all other classes that are not subclasses; you can't have different levels of protection for different invokers. > I thought I could achieve this by declaring String#check to be > protected, since according to the Pickaxe book: > > "Protected: Can be invoked only by objects of the defining class and > its subclasses." > > Well, "hello" is of type String, which is the defining class of > String#check, so I expected to be able to call it. If it's protected, it can only be called by methods inside the String class or subclasses. Was the object containing the method with this method call a subclass of String? cjs -- Curt Sampson +81 90 7737 2974 http://www.netbsd.org Don't you know, in this new Dark Age, we're all light. --XTC