aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2009-08-10 15:49:53 -0700
committerYehuda Katz <wycats@gmail.com>2009-08-11 15:03:53 -0700
commitccd1c5e521c020118b5bcfeb4cd5a651997b6806 (patch)
treece03925c5c787be5874f6adcfb45625c8996a3f6
parent4bf516e072f5279bdb462c6592e17b195fd9cf05 (diff)
downloadrails-ccd1c5e521c020118b5bcfeb4cd5a651997b6806.tar.gz
rails-ccd1c5e521c020118b5bcfeb4cd5a651997b6806.tar.bz2
rails-ccd1c5e521c020118b5bcfeb4cd5a651997b6806.zip
Allow superclass_delegating_accessor to take a block for initial set.
-rw-r--r--activesupport/lib/active_support/core_ext/class/delegating_attributes.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb b/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb
index fd029544c3..6c67df7f50 100644
--- a/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb
+++ b/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb
@@ -26,13 +26,14 @@ class Class
end
end
- def superclass_delegating_writer(*names)
+ def superclass_delegating_writer(*names, &block)
names.each do |name|
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
def self.#{name}=(value) # def self.property=(value)
@#{name} = value # @property = value
end # end
EOS
+ self.send("#{name}=", yield) if block_given?
end
end
@@ -42,8 +43,8 @@ class Class
# delegate to their superclass unless they have been given a
# specific value. This stops the strange situation where values
# set after class definition don't get applied to subclasses.
- def superclass_delegating_accessor(*names)
+ def superclass_delegating_accessor(*names, &block)
superclass_delegating_reader(*names)
- superclass_delegating_writer(*names)
+ superclass_delegating_writer(*names, &block)
end
end