class Parlour::RbiGenerator::Arbitrary
Represents miscellaneous Ruby code.
Attributes
Returns arbitrary code string.
Public Class Methods
Creates new arbitrary code.
@param code [String] The arbitrary code string. Indentation is added to
the beginning of each line.
# 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
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
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
# File lib/parlour/rbi_generator/arbitrary.rb, line 92 def generalize_from_rbi!; end
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
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
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