Class: MethodLog::Scope
- Inherits:
-
Object
- Object
- MethodLog::Scope
- Defined in:
- lib/method_log/scope.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #define(name) ⇒ Object
- #for(modules) ⇒ Object
-
#initialize(name, parent = nil, singleton = false) ⇒ Scope
constructor
A new instance of Scope.
- #lookup(name) ⇒ Object
- #method_identifier(name) ⇒ Object
- #root ⇒ Object
- #singleton ⇒ Object
Constructor Details
#initialize(name, parent = nil, singleton = false) ⇒ Scope
Returns a new instance of Scope.
29 30 31 32 33 34 |
# File 'lib/method_log/scope.rb', line 29 def initialize(name, parent = nil, singleton = false) @name = name @parent = parent @singleton = singleton @modules = {} end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
27 28 29 |
# File 'lib/method_log/scope.rb', line 27 def parent @parent end |
Instance Method Details
#define(name) ⇒ Object
48 49 50 |
# File 'lib/method_log/scope.rb', line 48 def define(name) @modules[name] = Scope.new(name, parent = self) end |
#for(modules) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/method_log/scope.rb', line 36 def for(modules) scope = self if modules.first == :root scope = root modules.unshift end modules.each do |mod| scope = scope.lookup(mod) || scope.define(mod) end scope end |
#lookup(name) ⇒ Object
52 53 54 |
# File 'lib/method_log/scope.rb', line 52 def lookup(name) @modules.fetch(name) { @parent.lookup(name) } end |
#method_identifier(name) ⇒ Object
60 61 62 |
# File 'lib/method_log/scope.rb', line 60 def method_identifier(name) [names.join('::'), separator, name].join end |
#root ⇒ Object
64 65 66 |
# File 'lib/method_log/scope.rb', line 64 def root parent.root end |