Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
defining Private/Protected class attributes
Carbon Monoxide
5/30/2008 11:17:00 AM
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
--
Posted via
http://www.ruby-...
.
3 Answers
David A. Black
5/30/2008 11:23:00 AM
0
Hi --
On Fri, 30 May 2008, 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 C
private
attr_accessor :a, :b
public
def initialize
end
end
David
--
Rails training from David A. Black and Ruby Power and Light:
INTRO TO RAILS June 9-12 Berlin
ADVANCING WITH RAILS June 16-19 Berlin
See
http://www.r...
for details and updates!
Siep Korteling
5/30/2008 1:39:00 PM
0
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)
--
Posted via
http://www.ruby-...
.
Carbon Monoxide
5/31/2008 4:12:00 AM
0
Siep Korteling 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!
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
defining Private/Protected class attributes
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password