Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/couchup/extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/couchup/extensions/string.rb', line 2

def blank?
  nil || strip.empty?
end

#camelizeObject



10
11
12
# File 'lib/couchup/extensions/string.rb', line 10

def camelize
  gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
end

#constantizeObject



6
7
8
# File 'lib/couchup/extensions/string.rb', line 6

def constantize
  Object.const_get(self)
end

#underscoreObject

cargo culted from rails inflector.



14
15
16
17
18
19
20
21
22
# File 'lib/couchup/extensions/string.rb', line 14

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