Class: Orbacle::ConstRef

Inherits:
Object
  • Object
show all
Defined in:
lib/orbacle/const_ref.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(const_name, is_absolute, nesting) ⇒ ConstRef

Returns a new instance of ConstRef.



19
20
21
22
23
# File 'lib/orbacle/const_ref.rb', line 19

def initialize(const_name, is_absolute, nesting)
  @const_name = const_name
  @is_absolute = is_absolute
  @nesting = nesting
end

Instance Attribute Details

#const_nameObject (readonly)

Returns the value of attribute const_name.



25
26
27
# File 'lib/orbacle/const_ref.rb', line 25

def const_name
  @const_name
end

#is_absoluteObject (readonly)

Returns the value of attribute is_absolute.



25
26
27
# File 'lib/orbacle/const_ref.rb', line 25

def is_absolute
  @is_absolute
end

#nestingObject (readonly)

Returns the value of attribute nesting.



25
26
27
# File 'lib/orbacle/const_ref.rb', line 25

def nesting
  @nesting
end

Class Method Details

.from_ast(ast, nesting) ⇒ Object



5
6
7
8
# File 'lib/orbacle/const_ref.rb', line 5

def self.from_ast(ast, nesting)
  full_name = AstUtils.const_to_string(ast)
  from_full_name(full_name, nesting)
end

.from_full_name(full_name, nesting) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/orbacle/const_ref.rb', line 10

def self.from_full_name(full_name, nesting)
  if full_name.start_with?("::")
    name = full_name[2..-1]
    new(ConstName.from_string(name), true, nesting)
  else
    new(ConstName.from_string(full_name), false, nesting)
  end
end

Instance Method Details

#==(other) ⇒ Object



39
40
41
42
43
# File 'lib/orbacle/const_ref.rb', line 39

def ==(other)
  const_name == other.const_name &&
    is_absolute == other.is_absolute &&
    nesting == other.nesting
end

#absolute?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/orbacle/const_ref.rb', line 27

def absolute?
  @is_absolute
end

#nameObject



35
36
37
# File 'lib/orbacle/const_ref.rb', line 35

def name
  const_name.name
end

#relative_nameObject



31
32
33
# File 'lib/orbacle/const_ref.rb', line 31

def relative_name
  const_name.to_string
end