Class: RubyLint::DefinitionBuilder::RubyMethod
- Defined in:
- lib/ruby-lint/definition_builder/ruby_method.rb
Overview
Definition builder for building method definitions. Receivers should be set from the outside (= the VM).
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#after_initialize ⇒ Object
Called after a new instance has been created.
-
#build ⇒ RubyLint::Definition::RubyMethod
Builds the definition for the method definition.
-
#has_receiver? ⇒ TrueClass|FalseClass
private
-
#method_name ⇒ String
private
-
#name_index ⇒ Numeric
private
-
#new_definition(parents) ⇒ RubyLint::Definition::RubyObject
private
-
#scope ⇒ RubyLint::Definition::RubyObject
Returns the scope to define the method in.
Methods inherited from Base
Constructor Details
This class inherits a constructor from RubyLint::DefinitionBuilder::Base
Instance Method Details
#after_initialize ⇒ Object
Called after a new instance has been created.
11 12 13 |
# File 'lib/ruby-lint/definition_builder/ruby_method.rb', line 11 def after_initialize @options[:type] ||= :instance_method end |
#build ⇒ RubyLint::Definition::RubyMethod
Builds the definition for the method definition.
21 22 23 |
# File 'lib/ruby-lint/definition_builder/ruby_method.rb', line 21 def build return new_definition([scope]) end |
#has_receiver? ⇒ TrueClass|FalseClass (private)
80 81 82 |
# File 'lib/ruby-lint/definition_builder/ruby_method.rb', line 80 def has_receiver? return node.type == :defs end |
#method_name ⇒ String (private)
45 46 47 |
# File 'lib/ruby-lint/definition_builder/ruby_method.rb', line 45 def method_name return node.children[name_index].to_s end |
#name_index ⇒ Numeric (private)
87 88 89 |
# File 'lib/ruby-lint/definition_builder/ruby_method.rb', line 87 def name_index return has_receiver? ? 1 : 0 end |
#new_definition(parents) ⇒ RubyLint::Definition::RubyObject (private)
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ruby-lint/definition_builder/ruby_method.rb', line 53 def new_definition(parents) type = [:type] instance_type = :instance # FIXME: setting the instance type of a method to a `class` is a bit of # a hack to ensure that class methods cause lookups inside them to be # performed on class level. if has_receiver? and [:receiver].class? type = :method instance_type = :class end return Definition::RubyMethod.new( :name => method_name, :parents => parents, :type => type, :instance_type => instance_type, :visibility => [:visibility], :line => node.line, :column => node.column, :file => node.file ) end |
#scope ⇒ RubyLint::Definition::RubyObject
Returns the scope to define the method in.
30 31 32 33 34 35 36 37 38 |
# File 'lib/ruby-lint/definition_builder/ruby_method.rb', line 30 def scope scope = vm.current_scope if has_receiver? and [:receiver] scope = [:receiver] end return scope end |