Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string_extensions.rb
Instance Method Summary collapse
-
#dehumanize ⇒ Object
Convert a string consisting of whitespace separated words into an underscore-delimited set of lowercase words.
-
#double_quote ⇒ Object
Return this string, surrounded by a double quote (“) on either side.
-
#quote(quote_char) ⇒ Object
Return this string, surrounded by quote_char on either side.
-
#single_quote ⇒ Object
Return this string, surrounded by a single quote (‘) on either side.
Instance Method Details
#dehumanize ⇒ Object
Convert a string consisting of whitespace separated words into an underscore-delimited set of lowercase words. This is the opposite of what ActiveSupport’s String.humanize method docs. Example: ‘Foo Bar’ -> ‘foo_bar’
10 11 12 |
# File 'lib/string_extensions.rb', line 10 def dehumanize titleize.gsub(/\W+/,'_').gsub(/\s+/,'_').gsub(/^_+|_+$/,'').underscore end |
#double_quote ⇒ Object
Return this string, surrounded by a double quote (“) on either side.
23 |
# File 'lib/string_extensions.rb', line 23 def double_quote; self.quote('"'); end |
#quote(quote_char) ⇒ Object
Return this string, surrounded by quote_char on either side.
15 16 17 |
# File 'lib/string_extensions.rb', line 15 def quote(quote_char) "#{quote_char}#{self}#{quote_char}" end |
#single_quote ⇒ Object
Return this string, surrounded by a single quote (‘) on either side.
20 |
# File 'lib/string_extensions.rb', line 20 def single_quote; self.quote("'"); end |