Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require "pathname"
- require "set"
- Dir.chdir("/opt/ruby/2.7/lib/ruby/gems/2.7.0/")
- list = Pathname.new("gems.rblist")
- if ARGV.delete("--refresh") or !list.exist? or list.mtime < Time.now-86400
- system "find gems/ -name '*.rb' > #{list}"
- end
- ugems = Set.new
- ufiles = Set.new
- ulines = Set.new
- list.readlines.each do |file| file.chomp!
- _,gem,path = file.split("/",3)
- gemname = gem[/\A(.*)-/,1]
- path =~ /\Alib\// or next
- ruby = File.read(file)
- ruby.scan(%r(^( *)def (?:\w+\.)?(?:\w+[!?]?)(.*end *$|(?:.*)(?:\n.*)*?\n\1end))) do
- dfn,body = $&.split("\n",2)
- dfn,body = dfn.split(/(?<=[\);])/,2) if body.nil?
- if dfn !~ /\*\*\w+/ and dfn =~ /\*(\w+)/
- var = $1
- delegation = body.lines.grep(/\w+[!?]?[ \(]([^,()]+, *)*\*#{var}\b/).first
- delegation ||= x=body.lines.grep(/\*#{var}\b/).first
- if delegation
- red=';31' if x
- puts "\e[1#{red}m#{file}\e[0m", dfn, delegation||"\e[37;2m#{body}\e[0m"
- ugems << gemname
- ufiles << file
- ulines << file+":"+dfn
- end
- end
- end
- end
- printf "%d matches in %d files of %d gems\n", ulines.size, ufiles.size, ugems.size
- #with *args in dfn and body
- #lib: 1949 matches in 1095 files of 225 gems
- #others: 256 matches in 167 files of 63 gems
- #with *args in dfn only
- #lib: 2899 matches in 2014 files of 433 gems
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement