Class: Astrolabe::Node

Inherits:
Object
  • Object
show all
Extended by:
RuboCop::NodePattern::Macros
Defined in:
lib/rubocop/ast_node.rb

Overview

RuboCop's extensions to Astrolabe::Node (which extends Parser::AST::Node)

Contribute as much of this as possible to the astrolabe gem If any of it is accepted, it can be deleted from here

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RuboCop::NodePattern::Macros

def_node_matcher, def_node_search

Class Method Details

.def_matcher(method_name, pattern_str) ⇒ Object

define both Node.method_name(node), and also node.method_name



17
18
19
20
# File 'lib/rubocop/ast_node.rb', line 17

def def_matcher(method_name, pattern_str)
  singleton_class.def_node_matcher method_name, pattern_str
  class_eval("def #{method_name}; Node.#{method_name}(self); end")
end

Instance Method Details

#asgn_method_call?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/rubocop/ast_node.rb', line 40

def asgn_method_call?
  method_name != :== && method_name.to_s.end_with?('=')
end

#method_nameObject

Destructuring



25
# File 'lib/rubocop/ast_node.rb', line 25

def_matcher :method_name, '{(send _ $_ ...) (block (send _ $_ ...) ...)}'

#multiline?Boolean

Predicates

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/rubocop/ast_node.rb', line 31

def multiline?
  expr = loc.expression
  expr && (expr.first_line != expr.last_line)
end

#single_line?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/rubocop/ast_node.rb', line 36

def single_line?
  !multiline?
end