Skip to content

Instantly share code, notes, and snippets.

@aereal aereal/ambiguous.rb
Created Dec 5, 2012

What would you like to do?
#!/usr/bin/env ruby
LOOK = `which look 2>/dev/null`.strip
abort "#{$0} requires |look| executable command" unless File.executable?(LOOK)
def calculate_clarity(word)
candidates = `#{LOOK} -f #{word}`.strip.lines
$?.success? ? candidates.count : 0
require "ruby_parser"
target_file = ARGF
sexp_tree =
definition_nodes = [:class, :cdecl, :lasgn, :args]
define_names = definition_nodes.flat_map {|node| sexp_tree.enum_for(:each_of_type, node).map {|exp| exp[1] } }
define_clarities = {|name| calculate_clarity(name) }
definitions =
threshold = 20
too_ambiguous_names = {|name, clarity| clarity >= threshold }
if $0 == __FILE__
too_ambiguous_names.each do |name, clarity|
puts "#{name} => #{clarity}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.