Module: Utils::IRB::Regexp
- Included in:
- Regexp
- Defined in:
- lib/utils/irb.rb
Overview
A module that extends Regexp functionality with additional pattern matching and display capabilities.
Provides enhanced regexp operations including match highlighting and shell command integration.
Instance Method Summary collapse
-
#show_match(string, success: -> s { Term::ANSIColor.green { s } }, failure: -> s { Term::ANSIColor.red { s } }) ⇒ String
The show_match method evaluates a string against the receiver pattern and highlights matching portions.
Instance Method Details
#show_match(string, success: -> s { Term::ANSIColor.green { s } }, failure: -> s { Term::ANSIColor.red { s } }) ⇒ String
The show_match method evaluates a string against the receiver pattern and highlights matching portions.
This method tests whether the provided string matches the pattern represented by the receiver. When a match is found, it applies the success proc to highlight the matched portion of the string. If no match is found, it applies the failure proc to indicate that no match was found.
730 731 732 733 734 735 736 |
# File 'lib/utils/irb.rb', line 730 def show_match( string, success: -> s { Term::ANSIColor.green { s } }, failure: -> s { Term::ANSIColor.red { s } } ) string =~ self ? "#{$`}#{success.($&)}#{$'}" : failure.("no match") end |