Skip to content

Commit

Permalink
Add comment about implementation of class_attribute
Browse files Browse the repository at this point in the history
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
pixeltrix committed Dec 6, 2012
1 parent 7b03d40 commit 8942035
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions activesupport/lib/active_support/core_ext/class/attribute.rb
Expand Up @@ -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
Expand Down

1 comment on commit 8942035

@fxn
Copy link
Member

@fxn fxn commented on 8942035 Dec 6, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Please sign in to comment.