Skip to content

Instantly share code, notes, and snippets.

@xaviervia
Created August 6, 2012 09:42
Show Gist options
  • Save xaviervia/3272882 to your computer and use it in GitHub Desktop.
Save xaviervia/3272882 to your computer and use it in GitHub Desktop.
class Demonstration
# Description of the method
def the_method required_argument, optional_one = true
"Do something, not much"
end
end
load "demonstration.rb"
lines = File.read("demonstration.rb").lines.to_a
methods = Demonstration.instance_methods false
summaries = {}
methods.each do |m_sym|
m = Demonstration.instance_method m_sym
line = lines[m.source_location.last - 1]
possible_comment = lines[m.source_location.last - 2].strip
comment = possible_comment if possible_comment.start_with? "#" # Repeat for previous line, do not forget!
params = m.parameters
summaries[m.name] = { :params => params,
:desc => comment }
end
puts summaries
# There. I just need to add some spice to the class, like Thor::Actions, and rendering for the comment, like Redcarpet::ANSI (Blackcarpet)
# The only question remaining is, Thor or not Thor?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment