Sha256: 55e905ddc1e49f26b4a825daaccc8aecd2ab2e719cc6fb814d12eddb469da653

Contents?: true

Size: 767 Bytes

Versions: 29

Compression:

Stored size: 767 Bytes

Contents

class Module #:nodoc:

    # This is here just to be able to call this method on all constants
    def subclass_of?(klass)
        return false
    end
    
    def parent_module(n=1)
        part = self.to_s.reverse.split('::', n+1)[n]
        return nil if part.blank?
        return const_get_full(part.reverse)
    end
    
    def last_name
        self.to_s.split('::')[-1].to_sym
    end
    
    def const_set_full(name, val)
        mod = self
        parts = name.to_s.split('::')
        parts[0..-2].each do |part|
            unless mod.const_defined?(part.to_sym)
                mod.const_set(part.to_sym, Module.new)
            end
            mod = mod.const_get(part.to_sym)
        end
        mod.const_set(parts[-1].to_sym, val)
    end
    
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
spiderfw-0.6.27 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.26 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.26.pre1 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.25 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.24 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.23 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.22 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.21 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.20 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.19 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.18 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.17 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.16 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.15 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.14 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.13 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.12 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.11 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.10 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.6.9 lib/spiderfw/utils/monkey/module.rb