Module: Waves::Utilities::String
- Included in:
- String
- Defined in:
- lib/utilities/string.rb
Overview
Utility methods mixed into String.
Instance Method Summary collapse
-
#/(string) ⇒ Object
Syntactic sugar for using File.join to concatenate the argument to the receiver.
-
#camel_case ⇒ Object
produces StringsLikeThis.
-
#lower_camel_case ⇒ Object
produces stringsLikeThis.
-
#snake_case ⇒ Object
produces strings_like_this.
- #text ⇒ Object
- #title_case ⇒ Object
Instance Method Details
#/(string) ⇒ Object
Syntactic sugar for using File.join to concatenate the argument to the receiver.
require "lib" / "utilities" / "string"
The idea is not original, but we can’t remember where we first saw it.
Waves::Utilities::Symbol defines the same method, allowing for :files / ‘afilename.txt’
16 17 18 |
# File 'lib/utilities/string.rb', line 16 def / ( string ) File.join(self,string.to_s) end |
#camel_case ⇒ Object
produces StringsLikeThis
26 27 28 |
# File 'lib/utilities/string.rb', line 26 def camel_case lower_camel_case.gsub(/^([a-z])/) { $1.upcase } end |
#lower_camel_case ⇒ Object
produces stringsLikeThis
21 22 23 |
# File 'lib/utilities/string.rb', line 21 def lower_camel_case gsub(/(_)(\w)/) { $2.upcase } end |
#snake_case ⇒ Object
produces strings_like_this
31 32 33 |
# File 'lib/utilities/string.rb', line 31 def snake_case gsub(/\s+/,'').gsub(/([a-z\d])([A-Z])/){ "#{$1}_#{$2}"}.tr("-", "_").downcase end |
#text ⇒ Object
39 40 41 |
# File 'lib/utilities/string.rb', line 39 def text gsub(/[\_\-\.\:]/,' ') end |
#title_case ⇒ Object
35 36 37 |
# File 'lib/utilities/string.rb', line 35 def title_case gsub(/(^|\s)\s*([a-z])/) { $1 + $2.upcase } end |