Skip to content

Instantly share code, notes, and snippets.

@rubyist
Created April 22, 2011 19:43
Show Gist options
  • Select an option

  • Save rubyist/937435 to your computer and use it in GitHub Desktop.

Select an option

Save rubyist/937435 to your computer and use it in GitHub Desktop.
rails cattr_reader
# File activesupport/lib/active_support/core_ext/class/attribute_accessors.rb, line 28
def cattr_reader(*syms)
options = syms.extract_options!
syms.each do |sym|
class_eval( unless defined? @@#{sym} @@#{sym} = nil end def self.#{sym} @@#{sym} end, __FILE__, __LINE__ + 1)
unless options[:instance_reader] == false
class_eval( def #{sym} @@#{sym} end, __FILE__, __LINE__ + 1)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment