Class: String

Inherits:
Object show all
Defined in:
lib/awsbase/support.rb,
lib/awsbase/support.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/awsbase/support.rb', line 132

def blank?
    empty? || strip.empty?
end

#constantizeObject

Constantize tries to find a declared constant with the name specified in the string. It raises a NameError when the name is not in CamelCase or is not initialized.

Examples

"Module".constantize #=> Module
"Class".constantize #=> Class


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/awsbase/support.rb', line 42

def constantize()
    camel_cased_word = self
    names = camel_cased_word.split('::')
    names.shift if names.empty? || names.first.empty?

    constant = Object
    names.each do |name|
#                constant = constant.const_get(name, false) || constant.const_missing(name)
         if Module.method(:const_get).arity == 1
            # ruby 1.8
            constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
        else
            # ruby 1.9
            constant = constant.const_get(name, false) || constant.const_missing(name)
        end
    end
    constant
end