Sha256: 6ad5328c793c2c43401216ccf512f102f2594b4c0b6229c0a337164ab12d6438
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 KB
Contents
#-- # Author:: Tyler Rick # Copyright:: Copyright (c) ActiveSupport authors # License:: # Submit to Facets?:: Yes. # Developer notes:: # * Tests incomplete... # Changes:: # * Copied from ActiveSupport. #++ $LOAD_PATH << File.expand_path(File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))) require 'facets/kernel/constant' class Module # Return all the parents of this module, ordered from nested outwards. The # receiver is not contained within the result. def parents parents = [] parts = name.split('::')[0..-2] until parts.empty? #parents << (parts * '::').constantize parents << constant(parts * '::') parts.pop end parents << Object unless parents.include? Object parents end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' module OuterModule; end module OuterModule::InnerModule; end class TheTest < Test::Unit::TestCase module InnerModule; end def test_1 assert_equal [Object], OuterModule.parents end def test_nesting assert_equal [OuterModule, Object], OuterModule::InnerModule.parents end def test_nesting_2 assert_equal [TheTest, Object], InnerModule.parents end end =end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
quality_extensions-1.4.0 | lib/quality_extensions/module/parents.rb |