Skip to content

Instantly share code, notes, and snippets.

@igaiga
Created January 11, 2023 05:43
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 igaiga/aa59aab0ffa1f7483a97ab2098bb219b to your computer and use it in GitHub Desktop.
Save igaiga/aa59aab0ffa1f7483a97ab2098bb219b to your computer and use it in GitHub Desktop.
require "typeprof"
target_code = <<~STR
result = []
a = [1,2,3].each do |x|
result << x * 2
end
p a
p result
STR
rb_files = rb_files = [["file.rb", target_code]]
rbs_files = []
output = StringIO.new("")
options = {}
options[:show_untyped] = true
options[:show_errors] = true
options[:show_indicator] = false
options[:show_typeprof_version] = false
config = TypeProf::ConfigData.new(
rb_files: rb_files,
rbs_files: rbs_files,
output: output,
options: options,
verbose: 0,
)
TypeProf.analyze(config)
p output = output.string
#=> "# Revealed types\n# file.rb:5 #=> [Integer, Integer, Integer]\n# file.rb:6 #=> Array[Integer]\n\n# Classes\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment