Class: Parlour::RbsGenerator::Block

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/parlour/rbs_generator/block.rb

Overview

Represents a block in a method signature. (This is not an RbsObject because it doesn’t generate a full line.)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, required) ⇒ Block

Creates a new block for a method signature.

Parameters:

  • type (Types::Proc)

    The type of this block.

  • required (T::Boolean)

    Whether this block is required.



14
15
16
17
# File 'lib/parlour/rbs_generator/block.rb', line 14

def initialize(type, required)
  @type = type
  @required = required
end

Instance Attribute Details

#requiredBoolean (readonly)

Whether this block is required.

Returns:

  • (Boolean)


37
38
39
# File 'lib/parlour/rbs_generator/block.rb', line 37

def required
  @required
end

#typeTypes::Proc (readonly)

The type of this block.

Returns:



32
33
34
# File 'lib/parlour/rbs_generator/block.rb', line 32

def type
  @type
end

Instance Method Details

#==(other) ⇒ Boolean

Returns true if this instance is equal to another method signature.

Parameters:

  • other (Object)

    The other instance. If this is not a MethodSignature (or a subclass of it), this will always return false.

Returns:

  • (Boolean)


25
26
27
# File 'lib/parlour/rbs_generator/block.rb', line 25

def ==(other)
  Block === other && type == other.type && required == other.required
end

#generate_rbs(options) ⇒ Array<String>

Generates the RBS string for this signature.

Parameters:

  • options (Options)

    The formatting options to use.

Returns:

  • (Array<String>)

    The RBS string, formatted as specified.



44
45
46
# File 'lib/parlour/rbs_generator/block.rb', line 44

def generate_rbs(options)
  ["#{required ? '' : '?'}{ #{type.generate_rbs} }"]
end