Module: QuoteUnquote::StringExtension
- Included in:
- String
- Defined in:
- lib/quote_unquote/string_ext.rb
Instance Method Summary collapse
-
#q(esc = nil) ⇒ Object
Wraps the String with single quotes.
-
#qq(esc = nil) ⇒ Object
Wraps the String with double quotes.
-
#uq(esc = nil) ⇒ Object
Unwraps single quotes.
-
#uqq(esc = nil) ⇒ Object
Unwraps double quotes.
Instance Method Details
#q(esc = nil) ⇒ Object
Wraps the String with single quotes
4 5 6 |
# File 'lib/quote_unquote/string_ext.rb', line 4 def q esc = nil %['#{esc ? self.gsub("'") { esc } : self}'] end |
#qq(esc = nil) ⇒ Object
Wraps the String with double quotes
9 10 11 |
# File 'lib/quote_unquote/string_ext.rb', line 9 def qq esc = nil %["#{esc ? self.gsub('"') { esc } : self}"] end |
#uq(esc = nil) ⇒ Object
Unwraps single quotes
14 15 16 |
# File 'lib/quote_unquote/string_ext.rb', line 14 def uq esc = nil (esc ? self.gsub(esc, "'") : self).gsub(/\A'|'\Z/, '') end |
#uqq(esc = nil) ⇒ Object
Unwraps double quotes
19 20 21 |
# File 'lib/quote_unquote/string_ext.rb', line 19 def uqq esc = nil (esc ? self.gsub(esc, '"') : self).gsub(/\A"|"\Z/, '') end |