Skip to content

Instantly share code, notes, and snippets.

@spickermann
Last active December 28, 2015 21:19
Show Gist options
  • Save spickermann/7564005 to your computer and use it in GitHub Desktop.
Save spickermann/7564005 to your computer and use it in GitHub Desktop.
Helper method that returns methods that might have a problem when upgrading from Ruby 1.8 to Ruby 1.9 because of shadowing block variables. With a lot of false positives...
# foo = 1
# 5.times do |foo|
# puts foo
# end
# return foo #=> returns 5 in Ruby 1.8, but 1 in Ruby 1.9
def files
Dir.glob('**/*.rb')
end
def methods(file)
/(($\s+?)def.*?\2end)/m.match(File.read(file))
end
def candidate(method)
/(\W(\w+)\W.*\|\2\|\W.*\W\2)/m.match(method)
end
files.each do |file|
if ms = methods(file)
ms.captures.each do |method|
if candidate(method)
puts "## #{file}"
puts "#{method}\n\n"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment