Sha256: 66c4a897447333e2d6d4c5172c6848cca8e2d78402aaffaa7c0e6716243fe44f
Contents?: true
Size: 1.15 KB
Versions: 21
Compression:
Stored size: 1.15 KB
Contents
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com # All files in this distribution are subject to the terms of the Ruby license. module Ramaze module CoreExtensions # Extensions for Kernel module Object # Original from Trans (Facets 1.4.5) # 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 # # require 'test/unit' # Test.constant("Unit::Assertions") # -> Test::Unit::Assertions # Test.constant("::Test::Unit") # -> Test::Unit def constant(const) const = const.to_s.dup if const.sub!(/^::/, '') base = Object elsif self.kind_of?(Module) base = self else base = self.class end const.split(/::/).inject(base){ |mod, name| mod.const_get(name) } end end end end
Version data entries
21 entries across 21 versions & 4 rubygems