Sha256: fde7fed146c012375af01f9bd5c3618babf79bf328aefd514201599d67e93348

Contents?: true

Size: 415 Bytes

Versions: 1

Compression:

Stored size: 415 Bytes

Contents

require 'tsort'
require 'class_ancestry_sort/version'

module ClassAncestrySort

  def self.asc(classes)
    List.new(classes).tsort
  end

  def self.desc(*classes)
    asc(*classes).reverse
  end

  class List < Array

    include TSort

    private

    def tsort_each_node(&block)
      each(&block)
    end

    def tsort_each_child(node, &block)
      (node.ancestors & self).each(&block)
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
class_ancestry_sort-0.1.0 lib/class_ancestry_sort.rb