Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/string_extensions.rb

Instance Method Summary collapse

Instance Method Details

#dehumanizeObject

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_quoteObject

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_quoteObject

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