Class: Decode::Language::Ruby::Code
- Inherits:
-
Object
- Object
- Decode::Language::Ruby::Code
- Defined in:
- lib/decode/language/ruby/code.rb
Overview
A Ruby-specific block of code.
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#relative_to ⇒ Object
readonly
Returns the value of attribute relative_to.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
- #The code text.(codetext.) ⇒ Object readonly
- #The language of the code.(languageofthecode.) ⇒ Object readonly
Instance Method Summary collapse
-
#extract(into = []) ⇒ Object
Extract definitions from the code.
-
#initialize(text, index, relative_to: nil, language:) ⇒ Code
constructor
Initialize a new code block.
- #The definition this code is relative to.=(definitionthiscodeisrelativeto. = (value)) ⇒ Object
- #The index to use for lookups.=(indextouse) ⇒ Object
- #The parsed syntax tree.=(parsedsyntaxtree. = (value)) ⇒ Object
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
#index ⇒ Object (readonly)
Returns the value of attribute index.
36 37 38 |
# File 'lib/decode/language/ruby/code.rb', line 36 def index @index end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
42 43 44 |
# File 'lib/decode/language/ruby/code.rb', line 42 def language @language end |
#relative_to ⇒ Object (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 |
#root ⇒ Object (readonly)
Returns the value of attribute root.
33 34 35 |
# File 'lib/decode/language/ruby/code.rb', line 33 def root @root end |
#text ⇒ Object (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 |