>* 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)] }
=> [#<struct Name first="James", last="Gray">, #<struct Name first="Dana", last="Gray">, #<struct Name first="Joe", last="Fair">]
>> # 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 #<struct Name first="James", last="Gray">
from (irb):28
James Edward Gray II
···
On Oct 3, 2006, at 7:20 AM, Tomasz Wegrzanowski wrote:
from :0