method
cattr_reader
![Moderate documentation Importance_2](https://d2vfyqvduarcvs.cloudfront.net/images/importance_2.png?1349367920)
v2.3.8 -
Show latest stable
-
2 notes -
Class: Class
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (0)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (38)
- 3.2.13 (0)
- 4.0.2 (0)
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
Register or
log in
to add new notes.
zvoase -
January 27, 2009 - (v2.1.0 - v2.2.1)
jackson_pires -
February 2, 2013
![Default_avatar_30](https://www.gravatar.com/avatar/3eed854319fb6d9ba9e00538d1ee76fd?size=30&default=http://apidock.com/images/default_avatar_30.png)
2 thanks
Description
Similar to Ruby’s built-in attr_reader, only it creates a class attribute reader method (as opposed to an instance attribute reader method).
![Default_avatar_30](https://www.gravatar.com/avatar/661e3632268c2bc668df33704b6938f9?size=30&default=http://apidock.com/images/default_avatar_30.png)
0 thanks
Other Example
##
class Exam cattr_reader :code, :description, :points, :instance_reader => false @@code = "EXM" @@description = "Sent Exam" @@points = 1000 end
In this case it’s possible to use
Exam.code # => EXM Exam.description # => Sent Exam Exam.points # => 1000