Method: Rodbot::Refinements#psub

Defined in:
lib/rodbot/refinements.rb

#psubString

Replace placeholders

Placeholders are all UPCASE and wrapped in [[ and ]]. They must match keys in the placeholder hash, however, these keys are Symbols and all downcase.

Examples:

placeholders = { sender: 'Oggy' }
'Hi, [[SENDER]]!'.psub(placeholders)   # => 'Hi, Oggy!'

Returns:

  • (String)

    string without placeholders



100
101
102
103
104
# File 'lib/rodbot/refinements.rb', line 100

refine String do
  def psub(placeholders)
    self.gsub(/\[\[.*?\]\]/) { placeholders[_1[2..-3].downcase.to_sym] }
  end
end