Class: RubyLint::DefinitionBuilder::RubyModule
- Defined in:
- lib/ruby-lint/definition_builder/ruby_module.rb
Overview
Definition builder used for building Ruby modules as well as providing the groundwork for building Ruby classes.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#build ⇒ Object
Creates a new module definition.
-
#module_name ⇒ Object
protected
Returns the name of the module.
-
#new_definition(parents) ⇒ RubyLint::Definition::RubyObject
protected
Creates a new RubyObject definition with the specified parent definitions.
-
#scope ⇒ RubyLint::Definition::RubyObject
Determines the scope to define the module in.
Methods inherited from Base
Constructor Details
This class inherits a constructor from RubyLint::DefinitionBuilder::Base
Instance Method Details
#build ⇒ Object
Creates a new module definition.
13 14 15 16 17 |
# File 'lib/ruby-lint/definition_builder/ruby_module.rb', line 13 def build mod = vm.global_constant('Module') return new_definition([mod, vm.current_scope]) end |
#module_name ⇒ Object (protected)
Returns the name of the module.
45 46 47 |
# File 'lib/ruby-lint/definition_builder/ruby_module.rb', line 45 def module_name return constant_name(node.children[0]) end |
#new_definition(parents) ⇒ RubyLint::Definition::RubyObject (protected)
Creates a new RubyObject definition with the specified parent definitions.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ruby-lint/definition_builder/ruby_module.rb', line 56 def new_definition(parents) definition = Definition::RubyObject.new( :name => module_name, :parents => parents, :reference_amount => 1, :type => :const, :line => node.line, :column => node.column, :file => node.file ) definition.define_self return definition end |
#scope ⇒ RubyLint::Definition::RubyObject
Determines the scope to define the module in.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ruby-lint/definition_builder/ruby_module.rb', line 24 def scope scope = vm.current_scope name_prefix = node.children[0].children[0] # name_prefix contains the constant path leading up to the name. For # example, if the name is `A::B::C` this node would contain `A::B`. if name_prefix found = ConstantPath.new(name_prefix).resolve(vm.current_scope) scope = found if found end return scope end |