Method: Pry::Hackage::Hack#replace

Defined in:
lib/pry/hack.rb

#replace(text, hash) ⇒ String

DSL function that acts like String#sub

Parameters:

  • text (String)

    The text that will be subject to the sub.

  • hash (Hash, String)

    If a hash, you must use the format :with => “text” and you may also supply :global? => true to apply a global substitution. See String#gsub

Returns:

  • (String)

    The string post operations.



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/pry/hack.rb', line 120

def replace(text, hash)
  if hash.is_a? Hash
    if hash[:global?].nil? || hash[:global?]
      return text.gsub(@PATTERN, hash[:with])
    else
      return text.sub(@PATTERN, hash[:with])
    end
  else
    return text.gsub(@PATTERN, hash)
  end
end