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, #multiline?, #nested?, #path, #qualified_form, #qualified_name, #start_with?, #text, #to_s

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”`.



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/decode/language/ruby/constant.rb', line 40

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



34
35
36
# File 'lib/decode/language/ruby/constant.rb', line 34

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

#short_formObject

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



30
31
32
# File 'lib/decode/language/ruby/constant.rb', line 30

def short_form
	@node.location.name.source
end