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::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:



29
30
31
32
# File 'lib/rubyzen/declarations/block_declaration.rb', line 29

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

Instance Attribute Details

#nodeRuboCop::AST::Node (readonly)

Returns:

  • (RuboCop::AST::Node)


22
23
24
# File 'lib/rubyzen/declarations/block_declaration.rb', line 22

def node
  @node
end

#parentMethodDeclaration, FileDeclaration (readonly)



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

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”



44
45
46
# File 'lib/rubyzen/declarations/block_declaration.rb', line 44

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)


37
38
39
# File 'lib/rubyzen/declarations/block_declaration.rb', line 37

def name
  method_name
end