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
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #extract(into = []) ⇒ Object
-
#initialize(text, index, relative_to: nil, language: relative_to&.language) ⇒ Code
constructor
A new instance of Code.
Constructor Details
#initialize(text, index, relative_to: nil, language: relative_to&.language) ⇒ Code
Returns a new instance of Code.
31 32 33 34 35 36 37 |
# File 'lib/decode/language/ruby/code.rb', line 31 def initialize(text, index, relative_to: nil, language: relative_to&.language) @text = text @root = ::Parser::CurrentRuby.parse(text) @index = index @relative_to = relative_to @language = language end |
Instance Attribute Details
#language ⇒ Object (readonly)
Returns the value of attribute language.
41 42 43 |
# File 'lib/decode/language/ruby/code.rb', line 41 def language @language end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
39 40 41 |
# File 'lib/decode/language/ruby/code.rb', line 39 def text @text end |
Instance Method Details
#extract(into = []) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/decode/language/ruby/code.rb', line 43 def extract(into = []) if @index traverse(@root, into) end return into end |