Class: String

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

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/support.rb', line 105

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

#camelizeObject



50
51
52
# File 'lib/support.rb', line 50

def camelize()
  self.dup.split(/_/).map{ |word| word.capitalize }.join('')
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
# File 'lib/support.rb', line 42

def constantize()
  unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self
    raise NameError, "#{self.inspect} is not a valid constant name!"
  end

  Object.module_eval("::#{$1}", __FILE__, __LINE__)
end

#firstObject



120
121
122
# File 'lib/support.rb', line 120

def first
  self
end