Sha256: 444e0b9cb18e88362ebf696159899c04e0a7d68fa5c2406c15f91d5129708002
Contents?: true
Size: 616 Bytes
Versions: 7
Compression:
Stored size: 616 Bytes
Contents
module Kernel # This is similar to +Module#const_get+ but is accessible at all levels, # and, unlike +const_get+, can handle module hierarchy. # # constant("Fixnum") # => Fixnum # constant(:Fixnum) # => Fixnum # # constant("Process::Sys") # => Process::Sys # constant("Regexp::MULTILINE") # => 4 # # CREDIT: Trans def constant(const) const = const.to_s.dup base = const.sub!(/^::/, '') ? Object : ( self.kind_of?(Module) ? self : self.class ) const.split(/::/).inject(base){ |mod, name| mod.const_get(name) } end end
Version data entries
7 entries across 6 versions & 1 rubygems