Skip to content
Browse files

Allow superclass_delegating_accessor to take a block for initial set.

  • Loading branch information...
1 parent 4bf516e commit ccd1c5e521c020118b5bcfeb4cd5a651997b6806 @wycats wycats committed
Showing with 4 additions and 3 deletions.
  1. +4 −3 activesupport/lib/active_support/core_ext/class/delegating_attributes.rb
View
7 activesupport/lib/active_support/core_ext/class/delegating_attributes.rb
@@ -26,13 +26,14 @@ def #{name}? # def only_reader?
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 @@ def self.#{name}=(value) # def self.property=(value)
# 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

0 comments on commit ccd1c5e

Please sign in to comment.
Something went wrong with that request. Please try again.