Class: String

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

Overview

Some useful additions to the String class

Instance Method Summary collapse

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_quotesObject



72
73
74
# File 'lib/foreplay.rb', line 72

def escape_double_quotes
  gsub('"', '\\"')
end

#fake_erbObject



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_newlineObject



76
77
78
# File 'lib/foreplay.rb', line 76

def remove_trailing_newline
  gsub(/\n\z/, '')
end