Class: String

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

Overview

:nodoc:all

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

:nodoc

Returns:

  • (Boolean)

57
58
59
# File 'lib/support/active_support_lite/blank.rb', line 57

def blank?
  self !~ /\S/
end

#camelize(first_letter_in_uppercase = true) ⇒ Object

:nodoc


30
31
32
33
34
35
36
# File 'lib/support/active_support_lite/string.rb', line 30

def camelize( first_letter_in_uppercase = true)
  if first_letter_in_uppercase
    gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
  else
    first + camelize(lower_case_and_underscored_word)[1..-1]
  end
end

#classifyObject

:nodoc


25
26
27
# File 'lib/support/active_support_lite/string.rb', line 25

def classify # DOES NOT SINGULARISE
  camelize(self.sub(/.*\./, ''))
end

#constantizeObject

:nodoc


17
18
19
20
21
22
# File 'lib/support/active_support_lite/string.rb', line 17

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

#demodulizeObject

:nodoc


12
13
14
# File 'lib/support/active_support_lite/string.rb', line 12

def demodulize
  gsub(/^.*::/, '')
end

#underscoreObject

:nodoc


3
4
5
6
7
8
9
# File 'lib/support/active_support_lite/string.rb', line 3

def underscore
  self.gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end