Sha256: de2635f9f11894feb0479a13eab503ae06855d371a706641f1c79215d1861ba4
Contents?: true
Size: 1.07 KB
Versions: 85
Compression:
Stored size: 1.07 KB
Contents
begin require 'active_support/core_ext/class/attribute' rescue LoadError # A dumbed down version of ActiveSupport's # Class#class_attribute helper. class Class def class_attribute(*attrs) instance_writer = true attrs.each do |name| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def self.#{name}() nil end def self.#{name}?() !!#{name} end def self.#{name}=(val) singleton_class.class_eval do define_method(:#{name}) { val } end if singleton_class? class_eval do def #{name} defined?(@#{name}) ? @#{name} : singleton_class.#{name} end end end val end def #{name} defined?(@#{name}) ? @#{name} : self.class.#{name} end def #{name}? !!#{name} end RUBY attr_writer name if instance_writer end end private def singleton_class? ancestors.first != self end end end
Version data entries
85 entries across 85 versions & 2 rubygems