Skip to content

Instantly share code, notes, and snippets.

@lsegal
Created April 6, 2010 04:56
Show Gist options
  • Save lsegal/357240 to your computer and use it in GitHub Desktop.
Save lsegal/357240 to your computer and use it in GitHub Desktop.
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