DecodeSourceDecodeLanguageRubyCode

class Code

A Ruby-specific block of code.

Definitions

def initialize(text, index, relative_to: nil, language: relative_to&.language)

Initialize a new code block.

Signature

parameter text String

The code text.

parameter index Index

The index to use.

parameter relative_to Definition

The definition this code is relative to.

parameter language Language

The language of the code.

Implementation

def initialize(text, index, relative_to: nil, language: relative_to&.language)
	@text = text
	@root = ::Prism.parse(text)
	@index = index
	@relative_to = relative_to
	@language = language
end

def extract(into = [])

Extract definitions from the code.

Signature

parameter into Array

The array to extract definitions into.

Implementation

def extract(into = [])
	if @index
		traverse(@root.value, into)
	end
	
	return into
end