Skip to content

Commit

Permalink
- Added auto-stringification for Regex::Matches objectes.
Browse files Browse the repository at this point in the history
Example:
	var str = 'Hello Sidef';
	var match = str.match(/^Hello (.+)/i);
	say match;        # prints: 'Sidef'
  • Loading branch information
trizen committed Sep 7, 2015
1 parent 8f6e9e7 commit 1428ebc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/Sidef/Types/Regex/Matches.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package Sidef::Types::Regex::Matches {

use 5.014;
use overload q{bool} => \&to_bool;
use overload
q{bool} => \&to_bool,
q{""} => \&to_s;

use parent qw(
Sidef::Object::Object
Expand Down Expand Up @@ -91,6 +93,11 @@ package Sidef::Types::Regex::Matches {

*ncap = \&named_captures;
*ncaps = \&named_captures;

sub to_s {
my ($self) = @_;
Sidef::Types::String::String->new(join(' ', @{$self->{captures}}));
}
};

1

0 comments on commit 1428ebc

Please sign in to comment.