Class: MiniRuby::Span

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/miniruby/span.rb

Overview

A collection of two positions: start and end

Constant Summary collapse

ZERO =
Span.new(Position::ZERO, Position::ZERO)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start, end_pos) ⇒ Span

Returns a new instance of Span.



16
17
18
19
# File 'lib/miniruby/span.rb', line 16

def initialize(start, end_pos)
  @start = start
  @end = end_pos
end

Instance Attribute Details

#endObject (readonly)

Returns the value of attribute end.



13
14
15
# File 'lib/miniruby/span.rb', line 13

def end
  @end
end

#startObject (readonly)

Returns the value of attribute start.



10
11
12
# File 'lib/miniruby/span.rb', line 10

def start
  @start
end

Instance Method Details

#==(other) ⇒ Object



30
31
32
33
34
# File 'lib/miniruby/span.rb', line 30

def ==(other)
  return false unless other.is_a?(Span)

  @start == other.start && @end == other.end
end

#inspectObject



37
38
39
# File 'lib/miniruby/span.rb', line 37

def inspect
  "S(#{@start.inspect}, #{@end.inspect})"
end

#join(other) ⇒ Object



25
26
27
# File 'lib/miniruby/span.rb', line 25

def join(other)
  Span.new(@start, other.end)
end