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

Joe R. 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?

Jeremy W. wrote:

Joe R. 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:

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

class Foo
attr_accessor :bar
end

foo = Foo.new

foo.bar = 7
puts foo.bar

=> 7

Kirk H.

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

attr_accessor defines both a writer and a reader

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

James Zhang

[email protected] wrote:

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.