Class: Rubyzen::Declarations::BlockDeclaration

Overview

Represents a Ruby block (do...end or { }).

Examples:

block = method.blocks.first
block.method_name   #=> "each"
block.call_sites    #=> CallSiteCollection
block.lines_of_code #=> 5

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Providers::AssignmentsProvider

#assignments

Methods included from Providers::ReturnsProvider

#return_expressions, #returns

Methods included from Providers::CallSiteProvider

#call_sites

Methods included from Providers::SourceCodeProvider

#source_code

Methods included from Providers::RaisesProvider

#raises

Methods included from Providers::RescuesProvider

#rescues

Methods included from Providers::LinesOfCodeProvider

#lines_of_code

Methods included from Providers::ClassNameProvider

#class_name

Methods included from Providers::LineNumberProvider

#line

Methods included from Providers::FilePathProvider

#file_path

Constructor Details

#initialize(node, parent) ⇒ BlockDeclaration

Returns a new instance of BlockDeclaration.

Parameters:



31
32
33
34
# File 'lib/rubyzen/declarations/block_declaration.rb', line 31

def initialize(node, parent)
  @node = node
  @parent = parent
end

Instance Attribute Details

#nodeRuboCop::AST::Node (readonly)

Returns:

  • (RuboCop::AST::Node)


24
25
26
# File 'lib/rubyzen/declarations/block_declaration.rb', line 24

def node
  @node
end

#parentMethodDeclaration, FileDeclaration (readonly)



27
28
29
# File 'lib/rubyzen/declarations/block_declaration.rb', line 27

def parent
  @parent
end

Instance Method Details

#method_nameString

Returns the method name the block is passed to.

Returns:

  • (String)

    e.g. “each”, “map”, “let”



46
47
48
# File 'lib/rubyzen/declarations/block_declaration.rb', line 46

def method_name
  node.method_name.to_s
end

#nameString

Returns the method name the block is passed to. Alias for #method_name.

Returns:

  • (String)


39
40
41
# File 'lib/rubyzen/declarations/block_declaration.rb', line 39

def name
  method_name
end