Class: Parlour::RbsGenerator::Extend

Inherits:
RbsObject show all
Defined in:
lib/parlour/rbs_generator/extend.rb

Overview

Represents an extend call.

Instance Attribute Summary collapse

Attributes inherited from RbsObject

#generator

Attributes inherited from TypedObject

#comments, #generated_by, #name

Instance Method Summary collapse

Methods inherited from TypedObject

#add_comment, #describe, #describe_tree

Constructor Details

#initialize(generator, type:, &block) ⇒ Extend

Creates a new extend call.

Parameters:



16
17
18
19
20
# File 'lib/parlour/rbs_generator/extend.rb', line 16

def initialize(generator, type:, &block)
  super(generator, '')
  @type = type
  yield_self(&block) if block
end

Instance Attribute Details

#typeTypes::TypeLike (readonly)

Returns The type to extend.

Returns:



34
35
36
# File 'lib/parlour/rbs_generator/extend.rb', line 34

def type
  @type
end

Instance Method Details

#==(other) ⇒ Boolean

Returns true if this instance is equal to another extend.

Parameters:

Returns:

  • (Boolean)


28
29
30
# File 'lib/parlour/rbs_generator/extend.rb', line 28

def ==(other)
  Extend === other && type == other.type
end

#describe_attrsObject



84
85
86
# File 'lib/parlour/rbs_generator/extend.rb', line 84

def describe_attrs
  [{type: type}] # avoid quotes
end

#generate_rbs(indent_level, options) ⇒ Array<String>

Generates the RBS lines for this extend.

Parameters:

  • indent_level (Integer)

    The indentation level to generate the lines at.

  • options (Options)

    The formatting options to use.

Returns:

  • (Array<String>)

    The RBS lines, formatted as specified.



47
48
49
# File 'lib/parlour/rbs_generator/extend.rb', line 47

def generate_rbs(indent_level, options)
  [options.indented(indent_level, "extend #{String === @type ? @type : @type.generate_rbs}")]
end

#merge_into_self(others) ⇒ void

This method returns an undefined value.

Given an array of Parlour::RbsGenerator::Extend instances, merges them into this one. This particular implementation will simply do nothing, as instances are only mergeable if they are indentical. You MUST ensure that #mergeable? is true for those instances.

Parameters:



79
80
81
# File 'lib/parlour/rbs_generator/extend.rb', line 79

def merge_into_self(others)
  # We don't need to change anything! We only merge identical extends
end

#mergeable?(others) ⇒ Boolean

Given an array of Parlour::RbsGenerator::Extend instances, returns true if they may be merged into this instance using #merge_into_self. This is always false.

Parameters:

Returns:

  • (Boolean)

    Whether this instance may be merged with them.



62
63
64
# File 'lib/parlour/rbs_generator/extend.rb', line 62

def mergeable?(others)
  others.all? { |other| self == other }
end