Skip to content

Instantly share code, notes, and snippets.

@sancarn
Last active July 2, 2018 13:54
Show Gist options
  • Save sancarn/e706281a070d1b7691e97b06eb8b0d55 to your computer and use it in GitHub Desktop.
Save sancarn/e706281a070d1b7691e97b06eb8b0d55 to your computer and use it in GitHub Desktop.
Retrieve all Classes and Methods in Ruby.

Ruby - Class and Methods Report

Attempts to produce a list of all available classes and methods available in the current Ruby instance.

Issues

Currently does not retrieve methods of Object class and it's ancestors (e.g. BasicObject) - Perhaps this should be added

arr = []
arr << "Ruby version " + ::RUBY_VERSION
arr << ""
Module.constants.each do |const|
if ::Module.const_defined? const
#If for whatever reason const_get fails, then rescue.
begin
obj = Module.const_get(const)
if obj
if obj.is_a? Class
# Class methods
arr << (obj.singleton_methods).sort.map do |method_sym|
obj.to_s + "::" + method_sym.to_s
end
# Instance methods
arr << (obj.instance_methods - (obj.superclass ? obj.superclass.instance_methods : []) - Object.methods).sort.map do |method_sym|
"#<" + obj.to_s + ">." + method_sym.to_s
end
elsif obj.is_a? Module
arr << (obj.methods - Module.methods).sort.map do |method_sym|
obj.to_s + "::" + method_sym.to_s
end
else
# Methods
arr << "::" + const.to_s
end
end
rescue
end
end
end
File.new("U:\\methods_#{::RUBY_VERSION}.txt","w").write(arr.flatten.sort.join("\n"))
arr = []
arr << "ICM version " + WSApplication::version if WSApplication
arr << "Ruby version " + ::RUBY_VERSION
arr << ""
Module.constants.each do |const|
if ::Module.const_defined? const
#If for whatever reason const_get fails, then rescue.
begin
obj = Module.const_get(const)
if obj
if obj.is_a? Class
# Class methods
arr << (obj.singleton_methods).sort.map do |method_sym|
obj.to_s + "::" + method_sym.to_s
end
# Instance methods
arr << (obj.instance_methods - (obj.superclass ? obj.superclass.instance_methods : []) - Object.methods).sort.map do |method_sym|
"#<" + obj.to_s + ">." + method_sym.to_s
end
elsif obj.is_a? Module
arr << (obj.methods - Module.methods).sort.map do |method_sym|
obj.to_s + "::" + method_sym.to_s
end
else
# Methods
arr << "::" + const.to_s
end
end
rescue
end
end
end
File.new("U:\\methods_#{::RUBY_VERSION}_#{WSApplication::version}.txt","w").write(arr.flatten.sort.join("\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment