Class: TypeProf::Signature
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
|
|
Inherits: | Object |
Defined in: | lib/typeprof/type.rb |
Instance Method Summary
Instance Method Details
#screen_name(iseq, scratch)
[ GitHub ]# File 'lib/typeprof/type.rb', line 856
def screen_name(iseq, scratch) fargs = @lead_tys.map {|ty| ty.screen_name(scratch) } farg_names = [] farg_names += iseq.locals[0, @lead_tys.size] if iseq if @opt_tys fargs += @opt_tys.map {|ty| "?" + ty.screen_name(scratch) } farg_names += iseq.locals[@lead_tys.size, @opt_tys.size] if iseq end if @rest_ty fargs << ("*" + @rest_ty.screen_name(scratch)) if iseq rest_index = iseq.fargs_format[:rest_start] farg_names << (rest_index ? iseq.locals[rest_index] : nil) end end if @post_tys fargs += @post_tys.map {|ty| ty.screen_name(scratch) } if iseq post_start = iseq.fargs_format[:post_start] farg_names += (post_start ? iseq.locals[post_start, @post_tys.size] : [nil] * @post_tys.size) end end if @kw_tys @kw_tys.each do |req, sym, ty| opt = req ? "" : "?" fargs << "#{ opt }#{ sym }: #{ ty.screen_name(scratch) }" end end if @kw_rest_ty all_val_ty = Type.bot @kw_rest_ty.each_child_global do |ty| if ty == Type.any val_ty = ty else # ty is a Type::Hash _key_ty, val_ty = ty.elems.squash end all_val_ty = all_val_ty.union(val_ty) end fargs << ("**" + all_val_ty.screen_name(scratch)) end if Config. [:show_parameter_names] farg_names = farg_names.map {|name| RBS::Parser::KEYWORDS.key?(name.to_s) ? "`#{name}`" : name } farg_names = farg_names.map {|name| name.is_a?(Integer) ? "noname_#{ name }" : name } fargs = fargs.zip(farg_names).map {|farg, name| name ? "#{ farg } #{ name }" : farg } end fargs = fargs.empty? ? "" : "(#{ fargs.join(", ") })" # Dirty Hack: Stop the iteration at most once! # I'll remove this hack if RBS removes the limitation of nesting blocks return fargs if caller_locations.any? {|frame| frame.label == "show_block_signature" } optional = false blks = [] @blk_ty.each_child_global do |ty| if ty.is_a?(Type::Proc) blks << ty else # XXX: how should we handle types other than Type.nil optional = true end end if blks != [] fargs << " " if fargs != "" fargs << "?" if optional fargs << scratch.show_block_signature(blks) end fargs end