Last active
August 29, 2015 13:56
-
-
Save mnzk/8893975 to your computer and use it in GitHub Desktop.
メソッドでパイプラインできた。(ただしメソッドの引数は1つに限定)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 追加したメソッドをパイプラインで使いたい | |
$foo = "abc" | Add-Member ScriptMethod Repeat{ | |
param($n) | |
$this * $n | |
} -PassThru | |
#Helper で対応 | |
filter Invoke-Method($method){ | |
$method.Invoke($_) | |
} | |
Set-Alias im Invoke-Method | |
5 | im $foo.Repeat #=> abcabcabcabcabc | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment