Class: String

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

Instance Method Summary collapse

Instance Method Details

#/(s) ⇒ Object



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

def /(s)
  File.join(self, s)
end

#blank?Boolean

Returns:

  • (Boolean)


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

def blank?
  self == ""
end

#classifyObject

Taken from Rails



11
12
13
14
15
# File 'lib/ext/string.rb', line 11

def classify
  string = self.underscore
  string = string.sub(/^[a-z\d]*/) { $&.capitalize }
  string.gsub(/(?:_|(\/))([a-z\d]*)/i) { $2.capitalize }.gsub('/', '::')
end

#dasherizeObject



26
27
28
# File 'lib/ext/string.rb', line 26

def dasherize
  self.underscore.gsub(/_/, '-')
end

#to_screen_nameObject



30
31
32
# File 'lib/ext/string.rb', line 30

def to_screen_name
  self.classify.sub(/(screen)*$/i, 'Screen')
end

#underscoreObject



17
18
19
20
21
22
23
24
# File 'lib/ext/string.rb', line 17

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