method

cattr_reader

v2.3.8 - Show latest stable - Class: Class
cattr_reader(*syms)
public

No documentation available.

# File activesupport/lib/active_support/core_ext/class/attribute_accessors.rb, line 10
  def cattr_reader(*syms)
    options = syms.extract_options!
    syms.each do |sym|
      next if sym.is_a?(Hash)
      class_eval("unless defined? @@\#{sym}\n@@\#{sym} = nil\nend\n\ndef self.\#{sym}\n@@\#{sym}\nend\n", __FILE__, __LINE__ + 1)

      unless options[:instance_reader] == false
        class_eval("def \#{sym}\n@@\#{sym}\nend\n", __FILE__, __LINE__ + 1)
      end
    end
  end

1Note

Other Example

jackson_pires ยท Feb 2, 2013
##

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