From: James Edward Gray II Date: 2006-10-03T23:57:57+09:00 Subject: Re: Private visibility should be removed from Ruby 2 [was: Caveats with #method_missing] On Oct 3, 2006, at 7:20 AM, Tomasz Wegrzanowski wrote: >> |* remove "protected" visibility completely > > Nobody uses "protected" (0 uses in standard library - can anybody > find some > code that actually uses it ?). Nobody understands it. I understand it just fine and have used it before. Here's an example where it might be needed: >> class Name < Struct.new(:first, :last) >> def full >> "#{first} #{last}" >> end >> ?> def last_first >> "#{last}, #{first}" >> end >> ?> def sortable >> [last, first] >> end >> protected :sortable >> ?> def <=>(other) >> sortable <=> other.sortable >> end >> end => nil >> names = [ %w[James Gray], ?> %w[Dana Gray], ?> %w[Joe Fair] ].inject(Array.new) { |a, n| a + [Name.new (*n)] } => [#, #, #] >> # OK, because protected allows the call to other.sortable: ?> names.sort.map { |n| n.last_first } => ["Fair, Joe", "Gray, Dana", "Gray, James"] >> # Not OK, because sortable is for internal use only: ?> names.first.sortable NoMethodError: protected method `sortable' called for # from (irb):28 from :0 James Edward Gray II