Skip to content

Instantly share code, notes, and snippets.

@obelisk68
Created May 2, 2017 11:17
Show Gist options
  • Save obelisk68/6decac799d95f0e8e8cec9679eda76e2 to your computer and use it in GitHub Desktop.
Save obelisk68/6decac799d95f0e8e8cec9679eda76e2 to your computer and use it in GitHub Desktop.
Created by RubyPico at Tue May 02 20:17:08 2017
def main
loop do
name = choise(class_list, combine: true)
clear
puts Module.const_get(name).info
puts
choise(["戻る"])
clear
end
end
def class_list
a = []
ObjectSpace.each_object(Module) do |o|
a.push o unless o.to_s.start_with? "#"
end
a.map { |e| e.to_s }.sort
end
class Module
def info
<<EOS
module #{to_s}
#{info_body}
EOS
end
end
class Class
def info
<<EOS
class #{to_s} < #{superclass}
#{info_body}
EOS
end
end
def info_body
r = []
e = included_modules - [Kernel]
r << " include #{e.join(", ")}" unless e.empty?
e = methods(false)
r << methods_str(e, "#{to_s}.") unless e.empty?
e = instance_methods(false)
r << methods_str(e) unless e.empty?
r.join("\n\n")
end
def methods_str(a, header = "")
a.map do |e|
" #{header}#{e}"
end.join("\n")
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment