Sha256: fdffc86712a26817c1d96a5d22765748da8ce4678c88f8c8b955c9a6a5d28833
Contents?: true
Size: 987 Bytes
Versions: 3
Compression:
Stored size: 987 Bytes
Contents
# Mail::TestRetriever uses cattr_accessor from rails. Since I don't want to include rails as a dependency # I'm just adding the Rails code here. # (Note, this is older Rails code slightly modified, but it should still work for what I need it for) class Class def cattr_accessor(*syms, &blk) cattr_reader(*syms) cattr_writer(*syms, &blk) end def cattr_reader(*syms) syms.flatten.each do |sym| next if sym.is_a?(Hash) class_eval(<<-EOS, __FILE__, __LINE__ + 1) unless defined? @@#{sym} @@#{sym} = nil end def self.#{sym} @@#{sym} end EOS end end def cattr_writer(*syms) syms.flatten.each do |sym| class_eval(<<-EOS, __FILE__, __LINE__ + 1) unless defined? @@#{sym} @@#{sym} = nil end def self.#{sym}=(obj) @@#{sym} = obj end EOS self.send("#{sym}=", yield) if block_given? end end end
Version data entries
3 entries across 3 versions & 1 rubygems