Class: Decode::Language::Ruby::Constant

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

Overview

A Ruby-specific constant.

Instance Attribute Summary

Attributes inherited from Definition

#The comment lines which directly preceeded the definition., #The language the symbol is defined within., #The path to the definition, relative to the parent., #The source file containing this definition., #comments, #language, #parent, #path, #source, #visibility

Instance Method Summary collapse

Methods inherited from Definition

#:public, :private, :protected=, #The parent definition, defining lexical scope.=, #The symbol name e.g. `:Decode`.=, #container?, #convert, #coverage_relevant?, #documentation, #documented?, #full_path, #initialize, #inspect, #location, #multiline?, #name, #nested?, #public?, #qualified_form, #qualified_name, #start_with?, #text

Constructor Details

This class inherits a constructor from Decode::Definition

Instance Method Details

#long_formObject

The long form of the constant. e.g. ‘NAME = “Alice”`.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/decode/language/ruby/constant.rb', line 26

def long_form
  if @node.location.start_line == @node.location.end_line
    @node.location.slice
  elsif @node.value&.type == :array_node
    "#{@node.name} = [...]"
  elsif @node.value&.type == :hash_node
    "#{@node.name} = {...}"
  else
    self.short_form
  end
end

#nested_nameObject

Generate a nested name for the constant.



20
21
22
# File 'lib/decode/language/ruby/constant.rb', line 20

def nested_name
  "::#{@name}"
end

#short_formObject

The short form of the constant. e.g. ‘NAME`.



15
16
17
# File 'lib/decode/language/ruby/constant.rb', line 15

def short_form
  @node.name.to_s
end