Module: Utils::IRB::Regexp
- Included in:
- Regexp
- Defined in:
- lib/utils/irb.rb
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.
685 686 687 688 689 690 691 |
# File 'lib/utils/irb.rb', line 685 def show_match( string, success: -> s { Term::ANSIColor.green { s } }, failure: -> s { Term::ANSIColor.red { s } } ) string =~ self ? "#{$`}#{success.($&)}#{$'}" : failure.("no match") end |