Class: RKelly::CharRange

Inherits:
Object
  • Object
show all
Defined in:
lib/rkelly/char_range.rb

Overview

Represents a syntax element location in source code - where it begins and where it ends.

It’s a value object - it can’t be modified.

Constant Summary collapse

EMPTY =

A re-usable empty range

CharRange.new(CharPos::EMPTY, CharPos::EMPTY)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to) ⇒ CharRange

Returns a new instance of CharRange.



13
14
15
16
# File 'lib/rkelly/char_range.rb', line 13

def initialize(from, to)
  @from = from
  @to = to
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



11
12
13
# File 'lib/rkelly/char_range.rb', line 11

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



11
12
13
# File 'lib/rkelly/char_range.rb', line 11

def to
  @to
end

Instance Method Details

#next(string) ⇒ Object

Creates a new range that immediately follows this one and contains the given string.



20
21
22
# File 'lib/rkelly/char_range.rb', line 20

def next(string)
  CharRange.new(@to.next(string[0]), @to.next(string))
end

#to_sObject Also known as: inspect



24
25
26
# File 'lib/rkelly/char_range.rb', line 24

def to_s
  "<#{@from}...#{@to}>"
end