Permalink
Browse files

Implement respectable version of Hash.ACCEPTS.

  • Loading branch information...
1 parent 6231d24 commit 69a3432d221934d6719ddbb4316d51f924af9149 @colomon colomon committed May 7, 2013
Showing with 17 additions and 0 deletions.
  1. +17 −0 lib/CORE.setting
View
@@ -1996,6 +1996,23 @@ my class Hash does Associative {
method fmt($format = "%s\t%s", $sep = "\n") {
self.pairs.map({ .fmt($format) }).join($sep)
}
+
+ method ACCEPTS($x) {
+ return $x.^does(self) unless self.defined;
+
+ sub contains-keys(%a, %b) {
+ for %a.keys -> $k { return False unless %b{$k}:exists; }
+ True;
+ }
+
+ given $x {
+ when Hash { contains-keys(self, $x) && contains-keys($x, self); }
+ when Array { self{any @$x}:exists; }
+ when Regex { any(self.keys).match($x); }
+ when Cool { self{$x}:exists; }
+ False;
+ }
+ }
}
my class Whatever {

0 comments on commit 69a3432

Please sign in to comment.