Skip to content

Commit

Permalink
Slightly awkward but functional implementation of capitalize.
Browse files Browse the repository at this point in the history
  • Loading branch information
colomon committed Feb 26, 2010
1 parent 0b8098e commit b9b14f9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/Any-str.pm
Expand Up @@ -3,6 +3,12 @@ augment class Any {
pir::box__PI(pir::bytelength__IS(self))
}

# The spec has a more elegant approach for this,
# but this one works now.
our Str multi method capitalize() {
self.lc.split(/\w+/, :all).map({ .Str.ucfirst }).join('');
}

our Int multi method chars() is export {
pir::length__IS(self);
}
Expand Down Expand Up @@ -276,5 +282,6 @@ our proto sub uc($string) { $string.uc; }
our proto sub ucfirst($string) { $string.ucfirst; }
our proto sub lc($string) { $string.lc; }
our proto sub lcfirst($string) { $string.lcfirst; }
our proto sub capitalize($string) { $string.capitalize; }

# vim: ft=perl6

0 comments on commit b9b14f9

Please sign in to comment.