aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorMarcel Molina <marcel@vernix.org>2005-11-20 22:32:40 +0000
committerMarcel Molina <marcel@vernix.org>2005-11-20 22:32:40 +0000
commitbaa2ab5ac30404bce5b5fddaa0d37322280fb48e (patch)
treeabd7fef85ef4a167ec5941f6e614d5e57da11db1 /activesupport/lib
parent55a3979a098d05158066ea3e53d0cdb66e88638c (diff)
downloadrails-baa2ab5ac30404bce5b5fddaa0d37322280fb48e.tar.gz
rails-baa2ab5ac30404bce5b5fddaa0d37322280fb48e.tar.bz2
rails-baa2ab5ac30404bce5b5fddaa0d37322280fb48e.zip
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
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/object_and_class.rb21
1 files changed, 20 insertions, 1 deletions
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)