Class: Decode::Language::Ruby::Code

Inherits:
Object
  • Object
show all
Defined in:
lib/decode/language/ruby/code.rb

Overview

A Ruby-specific block of code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, index, relative_to: nil, language:) ⇒ Code

Initialize a new code block.



21
22
23
24
25
26
27
# File 'lib/decode/language/ruby/code.rb', line 21

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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



36
37
38
# File 'lib/decode/language/ruby/code.rb', line 36

def index
  @index
end

#languageObject (readonly)

Returns the value of attribute language.



42
43
44
# File 'lib/decode/language/ruby/code.rb', line 42

def language
  @language
end

#relative_toObject (readonly)

Returns the value of attribute relative_to.



39
40
41
# File 'lib/decode/language/ruby/code.rb', line 39

def relative_to
  @relative_to
end

#rootObject (readonly)

Returns the value of attribute root.



33
34
35
# File 'lib/decode/language/ruby/code.rb', line 33

def root
  @root
end

#textObject (readonly)

Returns the value of attribute text.



30
31
32
# File 'lib/decode/language/ruby/code.rb', line 30

def text
  @text
end

#The code text.(codetext.) ⇒ Object (readonly)



30
# File 'lib/decode/language/ruby/code.rb', line 30

attr :text

#The language of the code.(languageofthecode.) ⇒ Object (readonly)



42
# File 'lib/decode/language/ruby/code.rb', line 42

attr :language

Instance Method Details

#extract(into = []) ⇒ Object

Extract definitions from the code.



47
48
49
50
51
52
53
# File 'lib/decode/language/ruby/code.rb', line 47

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

#The definition this code is relative to.=(definitionthiscodeisrelativeto. = (value)) ⇒ Object



39
# File 'lib/decode/language/ruby/code.rb', line 39

attr :relative_to

#The index to use for lookups.=(indextouse) ⇒ Object



36
# File 'lib/decode/language/ruby/code.rb', line 36

attr :index

#The parsed syntax tree.=(parsedsyntaxtree. = (value)) ⇒ Object



33
# File 'lib/decode/language/ruby/code.rb', line 33

attr :root