Class: Parlour::RbiGenerator::Extend

Inherits:
RbiObject
  • Object
show all
Defined in:
lib/parlour/rbi_generator/extend.rb

Overview

Represents an extend call.

Instance Attribute Summary

Attributes inherited from RbiObject

#comments, #generated_by, #generator, #name

Instance Method Summary collapse

Methods inherited from RbiObject

#add_comment

Constructor Details

#initialize(generator, name: '', &block) ⇒ Extend

Creates a new extend call.

Parameters:

  • name (String) (defaults to: '')

    The name of the object to be extended.



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

def initialize(generator, name: '', &block)
  super(generator, name)
  yield_self(&block) if block
end

Instance Method Details

#==(other) ⇒ Boolean

Returns true if this instance is equal to another extend.

Parameters:

Returns:

  • (Boolean)


27
28
29
# File 'lib/parlour/rbi_generator/extend.rb', line 27

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

#describeString

Returns a human-readable brief string description of this code.

Returns:

  • (String)


82
83
84
# File 'lib/parlour/rbi_generator/extend.rb', line 82

def describe
  "Extend (#{name})"
end

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

Generates the RBI 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 RBI lines, formatted as specified.



42
43
44
# File 'lib/parlour/rbi_generator/extend.rb', line 42

def generate_rbi(indent_level, options)
  [options.indented(indent_level, "extend #{name}")]
end

#merge_into_self(others) ⇒ void

This method returns an undefined value.

Given an array of Parlour::RbiGenerator::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:



74
75
76
# File 'lib/parlour/rbi_generator/extend.rb', line 74

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



57
58
59
# File 'lib/parlour/rbi_generator/extend.rb', line 57

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