Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/sprout/string.rb
Direct Known Subclasses
Instance Method Summary (collapse)
-
- (Object) camel_case
"foo_bar".camel_case #=> "FooBar".
- - (Object) dash_case
-
- (Object) snake_case
"FooBar".snake_case #=> "foo_bar".
Instance Method Details
- (Object) camel_case
"foo_bar".camel_case #=> "FooBar"
10 11 12 13 |
# File 'lib/sprout/string.rb', line 10 def camel_case str = gsub(/^[a-z]|_+[a-z]/) { |a| a.upcase } str.gsub(/_/, '') end |
- (Object) dash_case
15 16 17 |
# File 'lib/sprout/string.rb', line 15 def dash_case self.snake_case.gsub('_', '-') end |
- (Object) snake_case
"FooBar".snake_case #=> "foo_bar"
5 6 7 |
# File 'lib/sprout/string.rb', line 5 def snake_case gsub(/\B[A-Z]/, '_\&').downcase end |