Class: RubyLint::MethodCall::Alias

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby-lint/method_call/alias.rb

Overview

The Alias class is used to evaluate the use of alias and alias_method.

Instance Attribute Summary

Attributes inherited from Base

#node, #vm

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

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

Instance Method Details

#alias_gvar(arguments, context) ⇒ Object (private)

See Also:



36
37
38
39
40
41
42
43
# File 'lib/ruby-lint/method_call/alias.rb', line 36

def alias_gvar(arguments, context)
  alias_name  = node.children[0].name
  source_name = node.children[1].name
  source      = context.lookup(:gvar, source_name)

  # Global variables should be added to the root scope.
  vm.definitions.add(:gvar, alias_name, source) if source
end

#alias_sym(arguments, context) ⇒ Object (private)

See Also:



24
25
26
27
28
29
30
31
# File 'lib/ruby-lint/method_call/alias.rb', line 24

def alias_sym(arguments, context)
  method_type = context.method_call_type
  alias_name  = arguments[0].value.to_s
  source_name = arguments[1].value.to_s
  source      = context.lookup(method_type, source_name)

  context.add(method_type, alias_name, source) if source
end

#evaluate(arguments, context, block = nil) ⇒ Object

See Also:



11
12
13
14
15
16
17
# File 'lib/ruby-lint/method_call/alias.rb', line 11

def evaluate(arguments, context, block = nil)
  if node.type == :alias and node.children[0].gvar?
    alias_gvar(arguments, context)
  else
    alias_sym(arguments, context)
  end
end