Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string.rb
Instance Method Summary collapse
- #camel_case ⇒ Object (also: #cc)
- #pluralize ⇒ Object
- #to_b ⇒ Object
- #to_n ⇒ Object
- #upper_camel_case ⇒ Object (also: #ucc)
Instance Method Details
#camel_case ⇒ Object Also known as: cc
3 4 5 6 |
# File 'lib/string.rb', line 3 def camel_case str = upper_camel_case return str[0,1].downcase + str[1, str.length] end |
#pluralize ⇒ Object
35 36 37 38 |
# File 'lib/string.rb', line 35 def pluralize return self + 's' if self[length-1, length] != 's' return self + 'es' if self[length-1, length] == 's' end |
#to_b ⇒ Object
40 41 42 |
# File 'lib/string.rb', line 40 def to_b self == 'true' end |
#upper_camel_case ⇒ Object Also known as: ucc
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/string.rb', line 9 def upper_camel_case str = String.new(self) str.downcase! str.gsub!(/-/,'_') str.gsub!(/ /,'_') empties = %w{! @ # $ % ^ & * ( ) , < . > ; : ' " / ? [ { ] } = + \\ |} empties.each do |empty| r = Regexp.new('\\'+empty) str.gsub!(r, '') end str.gsub!(/[^a-zA-Z0-9_\- ]/,'_') str = '_' + str.split.join('_') str.gsub!(/_(.)/) { $1.upcase } return str end |