Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/foreplay.rb
Overview
Some useful additions to the String class
Instance Method Summary collapse
- #ansi_attributes(*args) ⇒ Object
- #escape_double_quotes ⇒ Object
- #fake_erb ⇒ Object
- #remove_trailing_newline ⇒ Object
Instance Method Details
#ansi_attributes(*args) ⇒ Object
64 65 66 |
# File 'lib/foreplay.rb', line 64 def ansi_attributes(*args) "\e[#{args.join(';')}m#{self}\e[0m" end |
#escape_double_quotes ⇒ Object
72 73 74 |
# File 'lib/foreplay.rb', line 72 def escape_double_quotes gsub('"', '\\"') end |
#fake_erb ⇒ Object
68 69 70 |
# File 'lib/foreplay.rb', line 68 def fake_erb gsub(/(<%=\s+([^%]+)\s+%>)/) { |e| eval "_ = #{e.split[1]}" } # rubocop:disable Security/Eval end |
#remove_trailing_newline ⇒ Object
76 77 78 |
# File 'lib/foreplay.rb', line 76 def remove_trailing_newline gsub(/\n\z/, '') end |