Rails < 3.0 doesn't have DescendantsTracker.
 Instead of iterating over ObjectSpace (slow) the decision was made NOT to support
 class hierarchies with abstract base classes in Rails 2.x
518073
def model_attributes(model, ignored_tables, ignored_cols)
      return [] if model.abstract_class? && Rails::VERSION::MAJOR < 3

      if model.abstract_class?
        model.direct_descendants.reject {|m| ignored?(m.table_name, ignored_tables)}.inject([]) do |attrs, m|
          attrs.push(model_attributes(m, ignored_tables, ignored_cols)).flatten.uniq
        end
      elsif !ignored?(model.table_name, ignored_tables) && @existing_tables.include?(model.table_name)
        model.columns.reject { |c| ignored?(c.name, ignored_cols) }.collect { |c| c.name }
      else
        []
      end
    end
341856
def traverse(flag=nil,&op)
		op.call(self)
		all_children_deep(flag).each do |c|
			op.call(c)
		end
	end
1143511
def inherited_meths(opts = {})
      inheritance_tree[1..-1].inject([]) do |list, superclass|
        if superclass.is_a?(Proxy)
          list
        else
          list += superclass.meths(opts).reject do |o|
            next(false) if opts[:all]
            child(:name => o.name, :scope => o.scope) ||
              list.find {|o2| o2.name == o.name && o2.scope == o.scope }
          end
        end
      end
    end
455717
def flattened_children
      no_frags = []
      children.each do |node|
        if node.is_a? Rxhp::Fragment
          no_frags += node.children
        else
          no_frags.push node
        end
      end

      previous = nil
      no_consecutive_strings = []
      no_frags.each do |node|
        if node.is_a?(String) && previous.is_a?(String)
          previous << node
        else
          no_consecutive_strings.push node
          previous = node
        end
      end

      no_consecutive_strings
    end
1334552
def get_all_descendants(parent):
    """"""
    children = parent.__subclasses__()
    descendants = children[:]
    for child in children:
        descendants += get_all_descendants(child)
    return descendants
1350475
def ltree(column = :path, options: { cascade: true })
      cattr_accessor :ltree_path_column

      self.ltree_path_column = column

      if options[:cascade]
        after_update :cascade_update
        after_destroy :cascade_destroy
      end

      extend ClassMethods
      include InstanceMethods
    end
781255
function(selector) {

	var allMatches = localnwt.all(selector),
		testNode = this._node,
		ancestor = null,
		maxDepth = 0;

	if( allMatches.size() == 0 ) {
		return null;
	}

	while( true ) {

		// Iterate through all matches for each parent, and exit as soon as we have a match
		// Pretty bad performance, but super small. TODO: Omtimize
		allMatches.each(function (el) {
			if (el._node == testNode) {
				ancestor = el;
			}
		});

		var parentNode = testNode.parentNode;

		if( ancestor || !parentNode) { break; }
		testNode = parentNode;
	}

	if( ancestor ) {
		return ancestor;
	} else {
		return null;
	}
}
1027472
def getCounts
      result = {}
      @classes.each do |c|
        count = 0
        ObjectSpace.each_object(c){ count += 1 }
        result[c] = count
      end
      result
    end
129275
def __descendants(self):
        
        return itertools.chain(self.contents,
                               *[c.descendants for c in self.children])
1338657
def setup_backtrace_cleaner_path
      return unless Rails.backtrace_cleaner.instance_variable_get(:@root) == '/'
      Rails.backtrace_cleaner.instance_variable_set :@root, Rails.root.to_s
    end
786240
def setup_backtrace_cleaner
      setup_backtrace_cleaner_path
      return if ActiveRecordQueryTrace.level == :full

      remove_filters_and_silencers

      case ActiveRecordQueryTrace.level
      when :app
        Rails.backtrace_cleaner.add_silencer { |line| line !~ rails_root_regexp }
      when :rails
        Rails.backtrace_cleaner.add_silencer { |line| line =~ rails_root_regexp }
      end
    end
800446
def __get_descendants(node, dfs_data):
    """"""
    list_of_descendants = []

    stack = deque()

    children_lookup = dfs_data['children_lookup']

    current_node = node
    children = children_lookup[current_node]
    dfs_current_node = D(current_node, dfs_data)
    for n in children:
        dfs_child = D(n, dfs_data)
        # Validate that the child node is actually a descendant and not an ancestor
        if dfs_child > dfs_current_node:
            stack.append(n)

    while len(stack) > 0:
        current_node = stack.pop()
        list_of_descendants.append(current_node)
        children = children_lookup[current_node]
        dfs_current_node = D(current_node, dfs_data)
        for n in children:
            dfs_child = D(n, dfs_data)
            # Validate that the child node is actually a descendant and not an ancestor
            if dfs_child > dfs_current_node:
                stack.append(n)

    return list_of_descendants
150639
def method_missing(method, *args)
      return self[method] if has_key?(method) # eager loaded with :include
      association_key = :"#{@_resources_key}.#{method}"
      if (polymorphic_association = find_polymorphic_association(self[:links], method))
        attributes = polymorphic_association.last
        ids, type = Array(attributes[:id]), attributes[:type]
        resolved_association_key = :"#{@_resources_key}.#{type.downcase}"
        uri_association_key = "#{association_key}.id"

        extract_resources(ids, resolved_association_key, uri_association_key, *args)
      elsif self[:links] && self[:links].has_key?(method)
        ids = Array(self[:links][method])
        extract_resources(ids, association_key, association_key, *args)
      else
        super
      end
    end
159864
def node_ancestor(node, levels)
      while levels > 0
        node = node.node_parent
        return unless node
        levels -= 1
      end

      node
    end
1306140
def each_object(compressed: false, recursive: false, &block)
            return enum_for(__method__, compressed: compressed,
                                        recursive: recursive
                           ) unless block_given?

            @revisions.each do |revision|
                revision.each_object do |object|
                    block.call(object)

                    walk_object(object, &block) if recursive

                    if object.is_a?(ObjectStream) and compressed
                        object.each do |child_obj|
                            block.call(child_obj)

                            walk_object(child_obj) if recursive
                        end
                    end
                end
            end
        end
104571
def default_tree_traversal(root, leaves):
    
    objs = [('#', root)]
    while len(objs) > 0:
        path, obj = objs.pop()

        # name of child are json-pointer encoded, we don't have
        # to encode it again.
        if obj.__class__ not in leaves:
            objs.extend(map(lambda i: (path + '/' + i[0],) + (i[1],), six.iteritems(obj._children_)))

        # the path we expose here follows JsonPointer described here
        #   http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-07
        yield path, obj
228049
private Class<?> nextDecoratedClassInHierarchy(Class<?> previousTemplateClass,
                                                 Class<?> candidate) {
    if (candidate == previousTemplateClass) {
      // terminate the recursion
      return null;
    } else if (candidate == Object.class) {
      // this should never happen - we should terminate recursion first
      throw new IllegalStateException("Did not find previous extension");
    } else {
      boolean isDecorated = candidate.isAnnotationPresent(Decorated.class);

      if (isDecorated)
        return candidate;
      else
        return nextDecoratedClassInHierarchy(previousTemplateClass, candidate.getSuperclass());
    }
  }