aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/class
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/core_ext/class')
-rw-r--r--activesupport/lib/active_support/core_ext/class/attribute_accessors.rb5
-rw-r--r--activesupport/lib/active_support/core_ext/class/delegating_attributes.rb7
2 files changed, 7 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
index 74ce85a1c2..1602a609eb 100644
--- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
+++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
@@ -46,11 +46,12 @@ class Class
end # end
" unless options[:instance_writer] == false } # # instance writer above is generated unless options[:instance_writer] == false
EOS
+ self.send("#{sym}=", yield) if block_given?
end
end
- def cattr_accessor(*syms)
+ def cattr_accessor(*syms, &blk)
cattr_reader(*syms)
- cattr_writer(*syms)
+ cattr_writer(*syms, &blk)
end
end
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