Class: RubyLint::DefinitionBuilder::RubyMethod

Inherits:
Base
  • Object
show all
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

#node, #options, #vm

Instance Method Summary collapse

Methods inherited from Base

#constant_name, #initialize

Constructor Details

This class inherits a constructor from RubyLint::DefinitionBuilder::Base

Instance Method Details

#after_initializeObject

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

#buildRubyLint::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)

Returns:

  • (TrueClass|FalseClass)


80
81
82
# File 'lib/ruby-lint/definition_builder/ruby_method.rb', line 80

def has_receiver?
  return node.type == :defs
end

#method_nameString (private)

Returns:



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_indexNumeric (private)

Returns:

  • (Numeric)


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)

Parameters:

  • parents (Array)

    The parent definitions.

Returns:



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          = options[: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 options[:receiver].class?
    type          = :method
    instance_type = :class
  end

  return Definition::RubyMethod.new(
    :name          => method_name,
    :parents       => parents,
    :type          => type,
    :instance_type => instance_type,
    :visibility    => options[:visibility],
    :line          => node.line,
    :column        => node.column,
    :file          => node.file
  )
end

#scopeRubyLint::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 options[:receiver]
    scope = options[:receiver]
  end

  return scope
end