Permalink
Browse files

Add comment about implementation of class_attribute

To prevent future pull requests like #8435 add a comment about the
implementation of class_attribute using class_eval for performance.

[ci skip]
  • Loading branch information...
1 parent 7b03d40 commit 8942035f428c1d89219aa7569869b53a42d9a610 @pixeltrix pixeltrix committed Dec 6, 2012
Showing with 3 additions and 0 deletions.
  1. +3 −0 activesupport/lib/active_support/core_ext/class/attribute.rb
@@ -72,6 +72,9 @@ def class_attribute(*attrs)
instance_reader = options.fetch(:instance_accessor, true) && options.fetch(:instance_reader, true)
instance_writer = options.fetch(:instance_accessor, true) && options.fetch(:instance_writer, true)
+ # We use class_eval here rather than define_method because class_attribute
+ # may be used in a performance sensitive context therefore the overhead that
+ # define_method introduces may become significant.
attrs.each do |name|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def self.#{name}() nil end

1 comment on commit 8942035

Owner

fxn commented on 8942035 Dec 6, 2012

❤️

Please sign in to comment.