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

#comments, #language, #name, #parent

Instance Method Summary collapse

Methods inherited from Definition

#container?, #convert, #documentation, #initialize, #inspect, #location, #multiline?, #nested?, #path, #path_name, #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”`.



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

def long_form
	if @node.location.line == @node.location.last_line
		@node.location.expression.source
	elsif @node.children[2].type == :array
		"#{@name} = [...]"
	elsif @node.children[2].type == :hash
		"#{@name} = {...}"
	else
		self.short_form
	end
end

#nested_nameObject



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

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.location.name.source
end