Skip to content

Instantly share code, notes, and snippets.

@kkismd
Created June 3, 2018 10:04
Show Gist options
  • Save kkismd/c69bbe01d428aa651baf89197f33abfe to your computer and use it in GitHub Desktop.
Save kkismd/c69bbe01d428aa651baf89197f33abfe to your computer and use it in GitHub Desktop.
imitate sorbet typecheker
#! env ruby
class CodeSignature
def initialize(args)
@args = args
end
def returns(klass)
@ret = klass
puts "CodeSignature: @args = #{@args.inspect}"
puts "CodeSignature: @ret = #{@ret.inspect}"
self
end
end
class Module
def sig(args)
CodeSignature.new(args)
end
end
class A
sig(foo: Integer).returns(String)
def bar(foo)
foo.to_s
end
end
if $0 == __FILE__
a = A.new
a.bar(1)
a.bar("hoge")
end
@kkismd
Copy link
Author

kkismd commented Jun 3, 2018

RDLだと全部文字列で書くことになる

type '(Integer) -> String'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment