Defining Private/Protected class attributes

If I would like to define some private/protected class attributes, I
would have to list all their getters or setters under “private” like the
code below. Is there any way that makes it faster?

class HelloRuby
attr_accessor :a, :b

private #a load of getters and setters
:a
:a=
:b
:b=

public
def initialize
end
end

Carbon Monoxide wrote:

If I would like to define some private/protected class attributes, I
would have to list all their getters or setters under “private” like the
code below. Is there any way that makes it faster?

class HelloRuby
attr_accessor :a, :b

private #a load of getters and setters
:a
:a=
:b
:b=

public
def initialize
end
end

class Test
attr_accessor :a, :b

def pub
end

private

def not_pub
end

attr_accessor :d, :e
end

t=Test.new
t.pub
t.e

#=> private method `e’ called for #Test:0x3156460 (NoMethodError)

Hi –

On Fri, 30 May 2008, Carbon Monoxide wrote:

:a=
:b
:b=

public
def initialize
end
end

class C
private
attr_accessor :a, :b
public
def initialize
end
end

David

Siep K. wrote:

class Test
attr_accessor :a, :b

def pub
end

private

def not_pub
end

attr_accessor :d, :e
end

t=Test.new
t.pub
t.e

#=> private method `e’ called for #Test:0x3156460 (NoMethodError)

Thanks all!