Sha256: 5a71b7ed6f65c05d0d36b8e2beb7ee9cac3888efe75f9a7e8b2989183fd5f743

Contents?: true

Size: 906 Bytes

Versions: 32

Compression:

Stored size: 906 Bytes

Contents

class Class
  
  # Returns a new Object instance of the class name specified.
  # 
  # Examples:
  #   Class.new_instance_of("Orange") => #<Orange:0x376c0c>
  #   Class.new_instance_of("Animals::Dog") => #<Animals::Dog:0x376a2c>
  def self.new_instance_of(klass_name)
    klass_name.constantize.new
  end
  
  # This will through the ancestor tree of object and tell you if
  # that object is of the specified type.
  def class_is_a?(klass_name)
    self.ancestors.each do |an|
      if an == klass_name
        return true
      end
    end
    return false
  end
  
  # Returns an array of the classes parent classes.
  # 
  # Examples:
  #   Orange.parents # => [Citrus, Fruit, Object]
  #   Citrus.parents # => [Fruit, Object]
  #   Fruit.parents # => [Object]
  def parents
    ans = [self.superclass]
    until ans.last.superclass.nil?
      ans << ans.last.superclass
    end
    ans
  end
  
end
  

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
mack-facets-0.6.0 lib/extensions/class.rb
mack-facets-0.6.1.1 lib/mack-facets/extensions/class.rb
mack-facets-0.6.0.1 lib/extensions/class.rb
mack-facets-0.8.0.101 lib/mack-facets/extensions/class.rb
mack-facets-0.6.1 lib/mack-facets/extensions/class.rb
mack-facets-0.6.1.2 lib/mack-facets/extensions/class.rb
mack-facets-0.7.0 lib/mack-facets/extensions/class.rb
mack-facets-0.7.0.1 lib/mack-facets/extensions/class.rb
mack-facets-0.7.1 lib/mack-facets/extensions/class.rb
mack-facets-0.8.0.1 lib/mack-facets/extensions/class.rb
mack-facets-0.8.0.2 lib/mack-facets/extensions/class.rb
mack-facets-0.7.1.1 lib/mack-facets/extensions/class.rb
mack-facets-0.8.0.3 lib/mack-facets/extensions/class.rb
mack-facets-0.8.2 lib/mack-facets/extensions/class.rb
mack-facets-0.8.3 lib/mack-facets/extensions/class.rb
mack-facets-0.8.3.1 lib/mack-facets/extensions/class.rb
mack-facets-0.8.0 lib/mack-facets/extensions/class.rb
mack-facets-0.8.1 lib/mack-facets/extensions/class.rb
mack_ruby_core_extensions-0.1.24 lib/extensions/class.rb
mack_ruby_core_extensions-0.1.25 lib/extensions/class.rb