Created
April 6, 2010 04:56
-
-
Save lsegal/357240 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yard' | |
module YardObject | |
def source; yard_object.source end | |
def docstring; yard_object.docstring end | |
private | |
def yard_object | |
fname = source_location[0] | |
@@file_cache ||= {} | |
unless @@file_cache[fname] | |
@@file_cache[fname] = true | |
YARD.parse(fname) | |
end | |
@yard_object ||= YARD::Registry.at(owner.name + '#' + name.to_s) | |
end | |
end | |
class Method; include YardObject end | |
class UnboundMethod; include YardObject end | |
class Foo | |
# A docstring! | |
def foo | |
end | |
end | |
f = Foo.new | |
puts f.method(:foo).docstring | |
puts f.method(:foo).source | |
# A docstring! | |
# def foo | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment