Class: MethodLog::MethodFinder
- Inherits:
-
Parser::AST::Processor
- Object
- Parser::AST::Processor
- MethodLog::MethodFinder
- Defined in:
- lib/method_log/method_finder.rb
Instance Attribute Summary collapse
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
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.
12 13 14 15 16 17 18 |
# File 'lib/method_log/method_finder.rb', line 12 def initialize(source_file) @source_file = source_file @scope = Scope::Root.new @methods = {} ast = Parser::CurrentRuby.parse(source_file.source) process(ast) end |
Instance Attribute Details
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
10 11 12 |
# File 'lib/method_log/method_finder.rb', line 10 def methods @methods end |
Instance Method Details
#find(method_identifier) ⇒ Object
20 21 22 |
# File 'lib/method_log/method_finder.rb', line 20 def find(method_identifier) @methods[method_identifier] end |
#on_def(node) ⇒ Object
38 39 40 41 42 |
# File 'lib/method_log/method_finder.rb', line 38 def on_def(node) name, args_node, body_node = *node record_method_definition(@scope, name, node) super end |
#on_defs(node) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/method_log/method_finder.rb', line 44 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
24 25 26 27 28 29 |
# File 'lib/method_log/method_finder.rb', line 24 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
33 34 35 36 |
# File 'lib/method_log/method_finder.rb', line 33 def on_sclass(node) target_node = node.children.first with_scope(singleton_scope_for(target_node)) { super } end |