Sha256: 6f9c76e24184ff22a4ed82003db981303c6f03a63347c4ffd4373d623d319b99
Contents?: true
Size: 912 Bytes
Versions: 9
Compression:
Stored size: 912 Bytes
Contents
require 'set' module Opbeat module BetterAttrAccessor def attributes Hash[ self.class.attributes.map do |attr| [attr, send(attr)] end ] end def self.included(base) base.extend ClassMethods end module ClassMethods def attributes @attributes ||= Set.new if superclass.include? BetterAttrAccessor @attributes + superclass.attributes else @attributes end end def attr_accessor(attr, options = {}) @attributes ||= Set.new @attributes << attr.to_s define_method attr do if instance_variable_defined? "@#{attr}" instance_variable_get "@#{attr}" elsif options.key? :default instance_variable_set "@#{attr}", options[:default].dup end end attr_writer attr end end end end
Version data entries
9 entries across 9 versions & 2 rubygems