Class: Orbacle::ConstName

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elems) ⇒ ConstName

Returns a new instance of ConstName.

Raises:

  • (ArgumentError)


10
11
12
13
# File 'lib/orbacle/const_name.rb', line 10

def initialize(elems)
  @elems = elems
  raise ArgumentError if elems.empty?
end

Instance Attribute Details

#elemsObject (readonly)

Returns the value of attribute elems.



15
16
17
# File 'lib/orbacle/const_name.rb', line 15

def elems
  @elems
end

Class Method Details

.from_string(str) ⇒ Object

Raises:

  • (ArgumentError)


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

def self.from_string(str)
  raise ArgumentError if str.start_with?("::")
  new(str.split("::"))
end

Instance Method Details

#==(other) ⇒ Object



17
18
19
# File 'lib/orbacle/const_name.rb', line 17

def ==(other)
  elems == other.elems
end

#nameObject



21
22
23
# File 'lib/orbacle/const_name.rb', line 21

def name
  elems.last
end

#scopeObject



29
30
31
# File 'lib/orbacle/const_name.rb', line 29

def scope
  Scope.new(elems[0..-2], false)
end

#to_stringObject



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

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