Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/chisel/ruby/string.rb
Instance Method Summary collapse
-
#camelize ⇒ Object
Converts ‘foo/herp_derp’ to ‘Foo::HerpDerp’.
- #camelized? ⇒ Boolean
-
#underscore ⇒ Object
Converts ‘Foo::HerpDerp’ to ‘foo/herp_derp’.
- #underscored? ⇒ Boolean
Instance Method Details
#camelize ⇒ Object
Converts ‘foo/herp_derp’ to ‘Foo::HerpDerp’
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/chisel/ruby/string.rb', line 27 def camelize tokens = self.split('/') if tokens.count > 1 return (tokens.map { |token| token.camelize }).join('::') end result = '' capitalize = true for i in (0..(self.length - 1)) if self[i] == '_' capitalize = true elsif capitalize capitalize = false result << self[i].upcase else result << self[i] end end result end |
#camelized? ⇒ Boolean
7 8 9 |
# File 'lib/chisel/ruby/string.rb', line 7 def camelized? self[0].upcase == self[0] end |
#underscore ⇒ Object
Converts ‘Foo::HerpDerp’ to ‘foo/herp_derp’
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/chisel/ruby/string.rb', line 12 def underscore tokens = self.split('::') if tokens.count > 1 return (tokens.map { |token| token.underscore }).join('/') end result = '' for i in (0..(self.length - 1)) result << '_' if self[i] == self[i].upcase and i != 0 result << self[i].downcase end result end |
#underscored? ⇒ Boolean
3 4 5 |
# File 'lib/chisel/ruby/string.rb', line 3 def underscored? self[0].downcase == self[0] end |