Created
December 28, 2013 09:50
-
-
Save k-tsj/8157847 to your computer and use it in GitHub Desktop.
Type(pattern) annotations for Ruby
This file contains hidden or 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
require 'pattern-match' | |
class Module | |
def check(pattern, mid) | |
prepend Module.new { | |
define_method(mid) do |*args| | |
ret = super(*args) | |
match(ret) do | |
with(Kernel.eval(pattern, Kernel.binding)) { ret } | |
end | |
end | |
} | |
end | |
end | |
class C | |
check '_[Integer]', | |
def m | |
[0] | |
end | |
end | |
C.new.m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment