Sha256: 701b0a83dac28f8b263fb56ac808273e30a2b0df0cd00b47c67e1849462a041f
Contents?: true
Size: 1023 Bytes
Versions: 9
Compression:
Stored size: 1023 Bytes
Contents
# Heavily inspired by "core_ext/module/attribute_accessors" from activesupport (4.0.0.beta) module TheBigDB def self.mattr_reader(*syms) syms.each do |sym| raise NameError.new('invalid attribute name') unless sym =~ /^[_A-Za-z]\w*$/ class_eval(<<-EOS, __FILE__, __LINE__ + 1) @@#{sym} = nil unless defined? @@#{sym} def self.#{sym} @@#{sym} end EOS class_eval(<<-EOS, __FILE__, __LINE__ + 1) def #{sym} @@#{sym} end EOS end end def self.mattr_writer(*syms) syms.each do |sym| raise NameError.new('invalid attribute name') unless sym =~ /^[_A-Za-z]\w*$/ class_eval(<<-EOS, __FILE__, __LINE__ + 1) def self.#{sym}=(obj) @@#{sym} = obj end EOS class_eval(<<-EOS, __FILE__, __LINE__ + 1) def #{sym}=(obj) @@#{sym} = obj end EOS end end def self.mattr_accessor(*syms) mattr_reader(*syms) mattr_writer(*syms) end end
Version data entries
9 entries across 9 versions & 1 rubygems