Sha256: 56c92331f080a428368ccd9c97c3acc0047a84943c0fc07fc16ce1416dfe098f

Contents?: true

Size: 639 Bytes

Versions: 50

Compression:

Stored size: 639 Bytes

Contents

class Class
  # Provides a way to make class attributes that inherit.  Pass
  # in symbols for attribute names
  def class_attribute(*attrs)
    attrs.each do |name|
      define_singleton_method(name) { nil }

      ivar = "@#{name}"

      define_singleton_method("#{name}=") do |val|
        singleton_class.class_eval do
          remove_possible_method(name)
          define_method(name) { val }
        end

        val
      end
    end
  end

  # Removes a method if it is defined.
  def remove_possible_method(method)
    if method_defined?(method) || private_method_defined?(method)
      undef_method(method)
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
volt-0.9.6 lib/volt/extra_core/class.rb
volt-0.9.6.pre3 lib/volt/extra_core/class.rb
volt-0.9.6.pre2 lib/volt/extra_core/class.rb
volt-0.9.6.pre1 lib/volt/extra_core/class.rb
volt-0.9.5 lib/volt/extra_core/class.rb
volt-0.9.5.pre12 lib/volt/extra_core/class.rb
volt-0.9.5.pre11 lib/volt/extra_core/class.rb
volt-0.9.5.pre9 lib/volt/extra_core/class.rb
volt-0.9.5.pre8 lib/volt/extra_core/class.rb
volt-0.9.5.pre7 lib/volt/extra_core/class.rb
volt-0.9.5.pre6 lib/volt/extra_core/class.rb
volt-0.9.5.pre5 lib/volt/extra_core/class.rb
volt-0.9.5.pre4 lib/volt/extra_core/class.rb
volt-0.9.5.pre3 lib/volt/extra_core/class.rb
volt-0.9.5.pre2 lib/volt/extra_core/class.rb
volt-0.9.5.pre1 lib/volt/extra_core/class.rb
volt-0.9.4 lib/volt/extra_core/class.rb
volt-0.9.4.pre5 lib/volt/extra_core/class.rb
volt-0.9.4.pre3 lib/volt/extra_core/class.rb
volt-0.9.4.pre2 lib/volt/extra_core/class.rb