Skip to content

Instantly share code, notes, and snippets.

@lsegal
Created June 19, 2009 18:07
Show Gist options
  • Save lsegal/132759 to your computer and use it in GitHub Desktop.
Save lsegal/132759 to your computer and use it in GitHub Desktop.
require 'yard'
class ClassLineHandler < YARD::Handlers::Ruby::Base
handles :class
def process
obj = ClassObject.new(namespace, statement[0].source)
obj.line_end = statement[0].line + statement.source.split("\n").size - 1
end
end
class ModuleLineHandler < YARD::Handlers::Ruby::Base
handles :module
def process
obj = register ModuleObject.new(namespace, statement[0].source)
obj.line_end = statement[0].line + statement.source.split("\n").size - 1
end
end
class LegacyClassLineHandler < YARD::Handlers::Ruby::Legacy::Base
handles TkCLASS
def process
classname = statement.tokens.to_s[/^class\s+(#{NAMESPACEMATCH})/, 1]
obj = ClassObject.new(namespace, classname)
obj.line_end = statement.line + statement.to_s(true).split("\n").size - 1
end
end
class LegacyModuleLineHandler < YARD::Handlers::Ruby::Legacy::Base
handles TkMODULE
def process
modname = statement.tokens.to_s[/^module\s+(#{NAMESPACEMATCH})/, 1]
obj = register ModuleObject.new(namespace, modname)
obj.line_end = statement.line + statement.to_s(true).split("\n").size - 1
end
end
YARD::Parser::SourceParser.parser_type = :ruby18
YARD::Parser::SourceParser.parse_string <<-eof
module M
class A
def a; end
end
end
eof
obj = P("M::A")
p obj.line..obj.line_end
obj = P("M")
p obj.line..obj.line_end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment