From: Ian Macdonald Date: 2002-05-23T08:43:09+09:00 Subject: confused about access control Hi, I'm rather confused about access control. Observe this: irb(main):001:0> class String irb(main):002:1> protected irb(main):003:1> def undot! irb(main):004:2> sub!(/^\.\./, '.') irb(main):005:2> end irb(main):006:1> end nil irb(main):007:0> class Foo irb(main):008:1> foo = '..123' irb(main):009:1> foo.undot! irb(main):010:1> end NameError: protected method `undot!' called for "..123":String from (irb):9 Why does this fail? The pick-axe book says: "Protected methods can be invoked only by objects of the defining class and its subclasses." Well, foo is an instance of String, which is the class that defines the undot! method, so why does this not work? I'm clearly missing something obvious. Ian -- Ian Macdonald | Fourth Law of Thermodynamics: If the ian@caliban.org | probability of success is not almost one, | it is damn near zero. -- David Ellis | |