Skip to content

Instantly share code, notes, and snippets.

@ajs
Created October 13, 2016 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajs/079f1f9c7d0cf51e6c8cd9ed745beb30 to your computer and use it in GitHub Desktop.
Save ajs/079f1f9c7d0cf51e6c8cd9ed745beb30 to your computer and use it in GitHub Desktop.
use v6;
class Filename is Str {
# Do some filename type stuff, here...
}
sub MAIN(
:$foo is copy where { $foo = Filename.new: :value($foo) }
#= A filename argument.
) {
say $foo.IO.basename;
}
# The monkey-typing version follows:
# use MONKEY-TYPING;
# class Filename is Str {
# # Do some filename type stuff, here...
# }
# augment class Str { method Filename(Str:D:) { Filename.new(:value(self)) } }
# sub MAIN(
# Filename(Str) :$foo
# #= A filename argument.
# ) {
# say $foo.IO.basename;
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment