Sha256: e129ffd0c65e1cf56ae3d0235cd490d50e18e4c0a10368747c2ec28c9fdf3b62
Contents?: true
Size: 967 Bytes
Versions: 2
Compression:
Stored size: 967 Bytes
Contents
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com # All files in this distribution are subject to the terms of the Ruby license. # Extensions for Kernel module Kernel # 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 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ramaze-0.3.0 | lib/ramaze/snippets/kernel/constant.rb |
ramaze-0.3.5 | lib/ramaze/snippets/kernel/constant.rb |