class Decode::Language::Ruby::Definition

A Ruby-specific definition.

Attributes

node[R]

The parser syntax tree node.

Public Class Methods

new(node, *arguments, **options) click to toggle source

Initialize the definition from the syntax tree node.

Calls superclass method Decode::Definition::new
# File lib/decode/language/ruby/definition.rb, line 29
def initialize(node, *arguments, **options)
        super(*arguments, **options)
        
        @node = node
end

Public Instance Methods

multiline?() click to toggle source
# File lib/decode/language/ruby/definition.rb, line 42
def multiline?
        @node.location.line != @node.location.last_line
end
nested_name() click to toggle source
# File lib/decode/language/ruby/definition.rb, line 35
def nested_name
        "\##{@name}"
end
text() click to toggle source

The source code associated with the definition. @returns [String]

# File lib/decode/language/ruby/definition.rb, line 48
def text
        expression = @node.location.expression
        lines = expression.source.lines
        if lines.count == 1
                return lines.first
        else
                if indentation = expression.source_line[/\A\s+/]
                        # Remove all the indentation:
                        lines.each{|line| line.sub!(indentation, '')}
                end
                
                return lines.join
        end
end