Class: Steep::TypeInference::SendArgs::BlockPassArg

Inherits:
Object
  • Object
show all
Includes:
Equatable
Defined in:
lib/steep/type_inference/send_args.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Equatable

#==, #eql?, #hash

Constructor Details

#initialize(node:, block:) ⇒ BlockPassArg

Returns a new instance of BlockPassArg.



438
439
440
441
# File 'lib/steep/type_inference/send_args.rb', line 438

def initialize(node:, block:)
  @node = node
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



436
437
438
# File 'lib/steep/type_inference/send_args.rb', line 436

def block
  @block
end

#nodeObject (readonly)

Returns the value of attribute node.



435
436
437
# File 'lib/steep/type_inference/send_args.rb', line 435

def node
  @node
end

Instance Method Details

#block_missing?Boolean

Returns:

  • (Boolean)


457
458
459
# File 'lib/steep/type_inference/send_args.rb', line 457

def block_missing?
  !node && block&.required?
end

#compatible?Boolean

Returns:

  • (Boolean)


449
450
451
452
453
454
455
# File 'lib/steep/type_inference/send_args.rb', line 449

def compatible?
  if node
    block ? true : false
  else
    !block || block.optional?
  end
end

#no_block?Boolean

Returns:

  • (Boolean)


445
446
447
# File 'lib/steep/type_inference/send_args.rb', line 445

def no_block?
  !node && !block
end

#node_typeObject



476
477
478
479
480
481
482
483
484
485
486
# File 'lib/steep/type_inference/send_args.rb', line 476

def node_type
  raise unless block

  type = AST::Types::Proc.new(type: block.type, block: nil, self_type: block.self_type)

  if block.optional?
    type = AST::Types::Union.build(types: [type, AST::Builtin.nil_type])
  end

  type
end

#pairObject



465
466
467
468
469
470
471
472
473
474
# File 'lib/steep/type_inference/send_args.rb', line 465

def pair
  raise unless compatible?

  if node && block
    [
      node,
      block.type
    ]
  end
end

#unexpected_block?Boolean

Returns:

  • (Boolean)


461
462
463
# File 'lib/steep/type_inference/send_args.rb', line 461

def unexpected_block?
  node && !block
end