class Parlour::RbiGenerator::Arbitrary

Represents miscellaneous Ruby code.

Attributes

code[RW]

Returns arbitrary code string.

Public Class Methods

new(generator, code: '', &block) click to toggle source

Creates new arbitrary code.

@param code [String] The arbitrary code string. Indentation is added to

the beginning of each line.
Calls superclass method
# File lib/parlour/rbi_generator/arbitrary.rb, line 17
def initialize(generator, code: '', &block)
  super(generator, '')
  @code = code
  yield_self(&block) if block
end

Public Instance Methods

==(other) click to toggle source

Returns true if this instance is equal to another arbitrary code line.

@param other [Object] The other instance. If this is not a {Arbitrary} (or a

subclass of it), this will always return false.

@return [Boolean]

# File lib/parlour/rbi_generator/arbitrary.rb, line 33
def ==(other)
  Arbitrary === other && code == other.code
end
describe() click to toggle source

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

@return [String]

# File lib/parlour/rbi_generator/arbitrary.rb, line 87
def describe
  "Arbitrary code (#{code})"
end
generalize_from_rbi!() click to toggle source
# File lib/parlour/rbi_generator/arbitrary.rb, line 92
def generalize_from_rbi!; end
generate_rbi(indent_level, options) click to toggle source

Generates the RBI lines for this arbitrary code.

@param indent_level [Integer] The indentation level to generate the lines at. @param options [Options] The formatting options to use. @return [Array<String>] The RBI lines, formatted as specified.

# File lib/parlour/rbi_generator/arbitrary.rb, line 48
def generate_rbi(indent_level, options)
  code.split("\n").map { |l| options.indented(indent_level, l) }
end
merge_into_self(others) click to toggle source

Given an array of {Arbitrary} instances, merges them into this one. This particular implementation always throws an exception, because {mergeable?} is always false.

@param others [Array<RbiGenerator::RbiObject>] An array of other

{Arbitrary} instances.

@return [void]

# File lib/parlour/rbi_generator/arbitrary.rb, line 79
def merge_into_self(others)
  raise 'arbitrary code is never mergeable'
end
mergeable?(others) click to toggle source

Given an array of {Arbitrary} instances, returns true if they may be merged into this instance using {merge_into_self}. This is always false.

@param others [Array<RbiGenerator::RbiObject>] An array of other

{Arbitrary} instances.

@return [Boolean] Whether this instance may be merged with them.

# File lib/parlour/rbi_generator/arbitrary.rb, line 63
def mergeable?(others)
  false
end