defining Private/Protected class attributes

C

Carbon Monoxide

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
 
D

David A. Black

Hi --

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 C
private
attr_accessor :a, :b
public
def initialize
end
end


David
 
S

Siep Korteling

Carbon said:
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)
 
C

Carbon Monoxide

Siep said:
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top