Class: Regexp

Inherits:
Object show all
Defined in:
lib/regexp.rb

Overview

# Add file name, line number, line to captures_hash captures_hash = $~.pre_match.split(ā€œnā€).last captures_hash = $~.pre_match.count(ā€œnā€) + 1 captures_hash = $&

Instance Method Summary collapse

Instance Method Details

#gsub_format(input_str, format_str, context: {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/regexp.rb', line 29

def gsub_format(input_str, format_str, context: {})
  input_str.gsub(self) do
    format(
      format_str,
      context.merge($~.names.each_with_object({}) do |name, hash|
        hash[name.to_sym] = $~[name]
      end)
    )
  end
end