Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/ext/string.rb
Instance Method Summary collapse
- #/(s) ⇒ Object
- #blank? ⇒ Boolean
-
#classify ⇒ Object
Taken from Rails.
- #dasherize ⇒ Object
- #to_screen_name ⇒ Object
- #underscore ⇒ Object
Instance Method Details
#/(s) ⇒ Object
2 3 4 |
# File 'lib/ext/string.rb', line 2 def /(s) File.join(self, s) end |
#blank? ⇒ Boolean
6 7 8 |
# File 'lib/ext/string.rb', line 6 def blank? self == "" end |
#classify ⇒ Object
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 |
#dasherize ⇒ Object
26 27 28 |
# File 'lib/ext/string.rb', line 26 def dasherize self.underscore.gsub(/_/, '-') end |
#to_screen_name ⇒ Object
30 31 32 |
# File 'lib/ext/string.rb', line 30 def to_screen_name self.classify.sub(/(screen)*$/i, 'Screen') end |
#underscore ⇒ Object
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 |