Class: Orbacle::Scope

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elems, is_eigenclass) ⇒ Scope

Returns a new instance of Scope.



9
10
11
12
# File 'lib/orbacle/scope.rb', line 9

def initialize(elems, is_eigenclass)
  @elems = elems
  @is_eigenclass = is_eigenclass
end

Instance Attribute Details

#elemsObject (readonly)

Returns the value of attribute elems.



14
15
16
# File 'lib/orbacle/scope.rb', line 14

def elems
  @elems
end

Class Method Details

.emptyObject



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

def self.empty
  new([], false)
end

Instance Method Details

#==(other) ⇒ Object



51
52
53
# File 'lib/orbacle/scope.rb', line 51

def ==(other)
  @elems == other.elems && eigenclass? == other.eigenclass?
end

#absolute_strObject



43
44
45
# File 'lib/orbacle/scope.rb', line 43

def absolute_str
  elems.join("::")
end

#decreaseObject



29
30
31
32
33
34
35
36
37
# File 'lib/orbacle/scope.rb', line 29

def decrease
  if eigenclass?
    Scope.new(elems, false)
  elsif elems.empty?
    raise
  else
    Scope.new(elems[0..-2], false)
  end
end

#eigenclass?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/orbacle/scope.rb', line 47

def eigenclass?
  @is_eigenclass
end

#empty?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/orbacle/scope.rb', line 39

def empty?
  elems.empty?
end

#increase_by_eigenclassObject



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

def increase_by_eigenclass
  raise if eigenclass?
  Scope.new(elems, true)
end

#increase_by_ref(const_ref) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/orbacle/scope.rb', line 16

def increase_by_ref(const_ref)
  if const_ref.absolute?
    Scope.new(const_ref.const_name.elems, false)
  else
    Scope.new(elems + const_ref.const_name.elems, eigenclass?)
  end
end

#to_const_nameObject



59
60
61
# File 'lib/orbacle/scope.rb', line 59

def to_const_name
  ConstName.new(elems)
end

#to_sObject



55
56
57
# File 'lib/orbacle/scope.rb', line 55

def to_s
  absolute_str
end