Sha256: e02e714f06dbb2876a4349b80439600c381abb9a6cae1697d4dd28c30eb444ff

Contents?: true

Size: 1.44 KB

Versions: 23

Compression:

Stored size: 1.44 KB

Contents

class Object #:nodoc:
  def remove_subclasses_of(*superclasses)
    Class.remove_class(*subclasses_of(*superclasses))
  end

  def subclasses_of(*superclasses)
    subclasses = []
    ObjectSpace.each_object(Class) do |k|
      next if # Exclude this class if
        (k.ancestors & superclasses).empty? || # It's not a subclass of our supers
        superclasses.include?(k) || # It *is* one of the supers
        eval("! defined?(::#{k})") || # It's not defined.
        eval("::#{k}").object_id != k.object_id
      subclasses << k
    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 { |name| instance_variable_set(name, object.instance_variable_get(name)) }
  end
  
  def extend_with_included_modules_from(object)
    object.extended_by.each { |mod| extend mod }
  end

  def instance_values
    instance_variables.inject({}) do |values, name|
      values[name[1..-1]] = instance_variable_get(name)
      values
    end
  end
  
  unless defined? instance_exec # 1.9
    def instance_exec(*arguments, &block)
      block.bind(self)[*arguments]
    end
  end
end

Version data entries

23 entries across 23 versions & 5 rubygems

Version Path
jstorimer-deep-test-2.0.0 sample_rails_project/vendor/rails/activesupport/lib/active_support/core_ext/object/extending.rb
jstorimer-deep-test-1.4.0 sample_rails_project/vendor/rails/activesupport/lib/active_support/core_ext/object/extending.rb
jstorimer-deep-test-1.3.0 sample_rails_project/vendor/rails/activesupport/lib/active_support/core_ext/object/extending.rb
jstorimer-deep-test-1.2.0 sample_rails_project/vendor/rails/activesupport/lib/active_support/core_ext/object/extending.rb
jstorimer-deep-test-1.1.0 sample_rails_project/vendor/rails/activesupport/lib/active_support/core_ext/object/extending.rb
jstorimer-deep-test-1.0.0 sample_rails_project/vendor/rails/activesupport/lib/active_support/core_ext/object/extending.rb
jstorimer-deep-test-0.2.0 sample_rails_project/vendor/rails/activesupport/lib/active_support/core_ext/object/extending.rb
jstorimer-deep-test-0.1.0 sample_rails_project/vendor/rails/activesupport/lib/active_support/core_ext/object/extending.rb
activesupport-1.3.1 lib/active_support/core_ext/object/extending.rb
activesupport-1.4.4 lib/active_support/core_ext/object/extending.rb
activesupport-1.4.2 lib/active_support/core_ext/object/extending.rb
activesupport-1.4.1 lib/active_support/core_ext/object/extending.rb
activesupport-1.4.0 lib/active_support/core_ext/object/extending.rb
activesupport-1.3.0 lib/active_support/core_ext/object/extending.rb
activesupport-1.4.3 lib/active_support/core_ext/object/extending.rb
monetra-ruby-0.0.6 lib/monetra/active_support/core_ext/object/extending.rb
radiant-0.6.0 vendor/rails/activesupport/lib/active_support/core_ext/object/extending.rb
radiant-0.6.1 vendor/rails/activesupport/lib/active_support/core_ext/object/extending.rb
radiant-0.6.3 vendor/rails/activesupport/lib/active_support/core_ext/object/extending.rb
radiant-0.6.2 vendor/rails/activesupport/lib/active_support/core_ext/object/extending.rb