ManageIQ currently runs on Ruby on Rails 3. Aaron "tenderlove" Patterson presents his effort to migrate to RoR 4, which entails some changes in the code to take advantage of the latest advances in RoR.
For more on ManageIQ, see http://manageiq.org/
102. require 'ripper'
class MyParser < Ripper
def on_def name, _, _
# do something
end
end
parser = MyParser.new "some code"
parser.parse
103. class MyParser < Ripper
attr_reader :methods, :calls
def initialize code, file, line
super
@methods = []
@calls = []
end
def on_def name, *rest
@methods << name
end
alias :on_command :on_def
def on_defs target, dot, name, *args
@methods << name
end
def on_call target, dot, name
@calls << name
end
def on_fcall name
@calls << name
end
alias :on_symbol :on_fcall
alias :on_vcall :on_fcall
end
104. Find.find(ARGV[0]) do |file|
next if File.directory? file
ext = file[/(?<=.)w+$/]
next unless ext
case ext
when 'rb'
parser = MyParser.new(File.read(file),
file, 1)
parser.parse
when 'erb'
parser = MyParser.new
ERB.new(File.read(file)).src, file, 1
parser.parse
end
end