Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/core_ext/string.rb
Instance Method Summary collapse
-
#camel_cased ⇒ String
Returns a camel cased version of a String.
- #capitalized? ⇒ Boolean
-
#snake_cased ⇒ String
Returns a snake cases version of a String.
-
#without_trailing_whitespace ⇒ String
Returns ‘self` with all trailing whitespace removed.
Instance Method Details
#camel_cased ⇒ String
Returns a camel cased version of a String.
17 18 19 |
# File 'lib/core_ext/string.rb', line 17 def camel_cased split("_").map(&:capitalize).join end |
#capitalized? ⇒ Boolean
28 29 30 31 |
# File 'lib/core_ext/string.rb', line 28 def capitalized? c = self[0] c && c.upcase == c end |
#snake_cased ⇒ String
Returns a snake cases version of a String.
6 7 8 9 10 11 |
# File 'lib/core_ext/string.rb', line 6 def snake_cased r1 = /([A-Z]+)([A-Z][a-z])/ r2 = /([a-z\d])([A-Z])/ gsub(r1,'\1_\2').gsub(r2,'\1_\2').tr("-", "_").downcase end |
#without_trailing_whitespace ⇒ String
Returns ‘self` with all trailing whitespace removed.
24 25 26 |
# File 'lib/core_ext/string.rb', line 24 def without_trailing_whitespace lines.map(&:rstrip).join("\n") end |