Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Last active March 19, 2019 20:30
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 JoshCheek/ea42080e8cd20b630749342f23dbb491 to your computer and use it in GitHub Desktop.
Save JoshCheek/ea42080e8cd20b630749342f23dbb491 to your computer and use it in GitHub Desktop.
Undocumented core Ruby
# code mostly taken from here: https://github.com/pry/pry-doc/blob/9eb2d6f5408256a88d3a97f22d596ac6db14e7db/Rakefile
# (modified a little)
#
# NOTE: You'll need:
# * wget (I did `brew install wget`)
# * latest_ruby (I did `gem install latest_ruby`)
# * yard (I did `gem install yard`)
require 'latest_ruby'
def generate_docs_for(ruby_ver, latest_ruby)
path = download_ruby(latest_ruby)
unpackage_ruby(path)
in_ruby_dir do
generate_yard
replace_existing_docs(ruby_ver)
end
end
def download_ruby(ruby)
system "mkdir rubies"
system "wget #{ ruby.link } --directory-prefix=rubies --no-clobber"
File.join('rubies', ruby.filename)
end
def unpackage_ruby(path)
system "mkdir rubies/ruby"
system "tar xzvf #{ path } --directory=rubies/ruby"
end
def in_ruby_dir(&block)
Dir.chdir(Dir['rubies/ruby/*'].first, &block)
end
def generate_yard
system %{
bash -c "paste <(find . -maxdepth 1 -name '*.c') <(find ext -name '*.c') |
xargs yardoc --no-output"
}
end
def replace_existing_docs(ver)
system %|mkdir -p ../../../docs/#{ver} && cp -r .yardoc/* "$_"|
end
Dir.exist? "docs/26" or
generate_docs_for('26', Latest.ruby26)
require 'yard'
registry = YARD::Registry.load_yardoc "docs/26"
missing_examples = registry.reject do |entry|
# regexes taken from here: https://github.com/pry/pry/blob/7b53a54879673d005023b6f16d138c3a1b6cab75/lib/pry/helpers/documentation_helpers.rb#L15
docs = entry.docstring
docs.match?(%r{<code>(?:\s*\n)?(.*?)\s*</code>}m) ||
docs.match?(%r{<tt>(?:\s*\n)?(.*?)\s*</tt>}m) ||
docs.match?(/((?:^[ \t]+.+(?:\n+|\Z))+)/) ||
docs.match?(/`(?:\s*\n)?([^\e]*?)\s*`/)
end
puts missing_examples.map(&:path)
puts
puts "Num missing examples: #{missing_examples.size}"
require "pry"
binding().pry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment