Attr_reader + attr_writer?

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-forum.com/.

class Foo
attr_accessor :bar
end

foo = Foo.new

foo.bar = 7
puts foo.bar

=> 7

Kirk Haines

···

On Fri, 13 Oct 2006, 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.

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-forum.com/\.

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-forum.com/\.

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. :wink:

···

--
Posted via http://www.ruby-forum.com/\.

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.

David

--
                   David A. Black | dblack@wobblini.net
Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]
[1] Ruby for Rails | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org

dblack@wobblini.net wrote:

HI --

> 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.

···

On Fri, 13 Oct 2006, jyzhang wrote: