Class: MethodLog::MethodFinder
- Inherits:
-
Parser::AST::Processor
- Object
- Parser::AST::Processor
- MethodLog::MethodFinder
- Defined in:
- lib/method_log/method_finder.rb
Instance Method Summary collapse
- #find(method_identifier) ⇒ Object
-
#initialize(source_file) ⇒ MethodFinder
constructor
A new instance of MethodFinder.
- #on_def(node) ⇒ Object
- #on_defs(node) ⇒ Object
- #on_module(node) ⇒ Object (also: #on_class)
- #on_sclass(node) ⇒ Object
Constructor Details
#initialize(source_file) ⇒ MethodFinder
Returns a new instance of MethodFinder.
10 11 12 13 14 15 16 |
# File 'lib/method_log/method_finder.rb', line 10 def initialize(source_file) @source_file = source_file @scope = Scope::Root.new @methods = {} ast = Parser::CurrentRuby.parse(source_file.source) process(ast) end |
Instance Method Details
#find(method_identifier) ⇒ Object
18 19 20 |
# File 'lib/method_log/method_finder.rb', line 18 def find(method_identifier) @methods[method_identifier] end |
#on_def(node) ⇒ Object
36 37 38 39 40 |
# File 'lib/method_log/method_finder.rb', line 36 def on_def(node) name, args_node, body_node = *node record_method_definition(@scope, name, node) super end |
#on_defs(node) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/method_log/method_finder.rb', line 42 def on_defs(node) definee_node, name, args_node, body_node = *node scope = singleton_scope_for(definee_node) record_method_definition(scope, name, node) super end |
#on_module(node) ⇒ Object Also known as: on_class
22 23 24 25 26 27 |
# File 'lib/method_log/method_finder.rb', line 22 def on_module(node) const_node = node.children.first constants = process_const(const_node) new_constant = constants.pop with_scope(@scope.for(constants).define(new_constant)) { super } end |
#on_sclass(node) ⇒ Object
31 32 33 34 |
# File 'lib/method_log/method_finder.rb', line 31 def on_sclass(node) target_node = node.children.first with_scope(singleton_scope_for(target_node)) { super } end |