[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

attr_reader + attr_writer?

Joe Ruby

10/13/2006 12:32:00 AM

Is there a class method that combines attr_reader and attr_writer? I
thought I remember seeing some "cattr_*" method, but don't know what
that was.

Thanks,
Joe

--
Posted via http://www.ruby-....

6 Answers

khaines

10/13/2006 12:34:00 AM

0

Jeremy Woertink

10/13/2006 1:03:00 AM

0

Joe Ruby MUDCRAP-CE wrote:
> Is there a class method that combines attr_reader and attr_writer? I
> thought I remember seeing some "cattr_*" method, but don't know what
> that was.
>
> Thanks,
> Joe

I'm still new to this whole ruby and programming stuff, but doesn't
attr_accessor do both of those?

--
Posted via http://www.ruby-....

jyzhang

10/13/2006 8:47:00 AM

0

attr_accessor defines both a writer and a reader

cattr_* is for class variables... you know... the kind that looks like
@@var

James Zhang

Jeremy Woertink wrote:
> Joe Ruby MUDCRAP-CE wrote:
> > Is there a class method that combines attr_reader and attr_writer? I
> > thought I remember seeing some "cattr_*" method, but don't know what
> > that was.
> >
> > Thanks,
> > Joe
>
> I'm still new to this whole ruby and programming stuff, but doesn't
> attr_accessor do both of those?
>
> --
> Posted via http://www.ruby-....

dblack

10/13/2006 12:32:00 PM

0

Marc Heiler

10/13/2006 12:36:00 PM

0

Jeremy Woertink wrote:
> Joe Ruby MUDCRAP-CE wrote:
>> Is there a class method that combines attr_reader and attr_writer? I
>> thought I remember seeing some "cattr_*" method, but don't know what
>> that was.
>>
>> Thanks,
>> Joe
>
> I'm still new to this whole ruby and programming stuff, but doesn't
> attr_accessor do both of those?


yes, attr_accessor does this.

I was also toying with an attr_reader that allows ? for
read-vars ... ruby triggers crazy ideas. A haskell guy once said
that he liked ? at end of method names in Ruby. ;-)

--
Posted via http://www.ruby-....

Trans

10/13/2006 3:20:00 PM

0


dblack@wobblini.net wrote:
> HI --
>
> On Fri, 13 Oct 2006, jyzhang wrote:
>
> > attr_accessor defines both a writer and a reader
> >
> > cattr_* is for class variables... you know... the kind that looks like
> > @@var
>
> Ruby doesn't have any cattr_* methods, though. Also, if you write a
> wrapper around class variables, it would be better to call them
> something else, as the "attr" in "cattr" implies that you're dealing
> with an object attribute. Since class variables are shared by many
> objects, they're not actually representing attributes.

To be clear cattr methods create both instance level and class level
accessors using @@vars for storage. What would be a better name then
class attribute?

T.