attr_reader, etc. 
Author Message
 attr_reader, etc.

Check the Pickaxe p. 24, or online
http://www.*-*-*.com/ , under the heading
"Objects and Attributes".

There's not really much to say. The attr_reader method creates an
instance variable and a method that returns its value. The attr_writer
method creates an instance variable and a method that sets its value. The
attr_accessor method does both.

class MyClass
        attr_reader :foo
end

is shorthand for

class MyClass
        def foo

        end
end

Similarly,

class MyClass
        attr_writer :foo
end

is shorthand for

class MyClass
        def foo=(f)

        end
end

and finally

class MyClass
        attr_accessor :foo
end

is shorthand for

class MyClass
        def foo

        end
        def foo=(f)

        end
end

Quote:

> I'm having some confusion with the use of
> attr_reader/writer/accessor,etc.
> Could someone point me to a document that explains clearly, and in
> depth?



Fri, 10 Jun 2005 06:17:57 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. attr_reader :foo?

2. attr_reader/writer vs. attr_accessor w/ access control

3. druby/attr_reader problem

4. attr_reader for great number of instance vars

5. attr_accessor, attr_reader question

6. Ruby code for attr, attr_accessor, attr_reader, attr_writer ?

7. p24 of Programming Ruby, attr_reader

8. help attr_reader

9. Algorithm etc etc

10. Overloading and / or / = / etc etc

11. Demos, PMode, Graphics, Docs, Tutorials, etc, etc

12. Demos, PMode, Graphics, Docs, Tutorials, etc, etc

 

 
Powered by phpBB® Forum Software