From baa2ab5ac30404bce5b5fddaa0d37322280fb48e Mon Sep 17 00:00:00 2001 From: Marcel Molina Date: Sun, 20 Nov 2005 22:32:40 +0000 Subject: Add extended_by, extend_with_included_modules_from and copy_instance_variables_from to Object. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3113 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/active_support/core_ext/object_and_class.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/object_and_class.rb b/activesupport/lib/active_support/core_ext/object_and_class.rb index 1e080d35a4..7864c1a9dc 100644 --- a/activesupport/lib/active_support/core_ext/object_and_class.rb +++ b/activesupport/lib/active_support/core_ext/object_and_class.rb @@ -13,7 +13,26 @@ class Object #:nodoc: end subclasses end - + + def extended_by + ancestors = class << self; ancestors end + ancestors.select { |mod| mod.class == Module } - [ Object, Kernel ] + end + + def copy_instance_variables_from(object, exclude = []) + exclude += object.protected_instance_variables if + object.respond_to? :protected_instance_variables + + instance_variables = object.instance_variables - exclude.map { |name| name.to_s } + instance_variables.each do |name| + instance_variable_set name, object.instance_variable_get(name) + end + end + + def extend_with_included_modules_from(object) + object.extended_by.each { |mod| extend mod } + end + # "", " ", nil, [], and {} are blank def blank? if respond_to?(:empty?) && respond_to?(:strip) -- cgit v1.2.3