Sha256: 69412d2b071621fccd73ad658a8e0c312cba57b41de827422480f325e17a9c6e

Contents?: true

Size: 713 Bytes

Versions: 6

Compression:

Stored size: 713 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)
        return const_get_full(self.to_s.reverse.split('::', n+1)[n].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

6 entries across 6 versions & 1 rubygems

Version Path
spiderfw-0.5.19 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.5.18 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.5.17 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.5.16 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.5.15 lib/spiderfw/utils/monkey/module.rb
spiderfw-0.5.14 lib/spiderfw/utils/monkey/module.rb