Class: RKelly::CharRange
- Inherits:
-
Object
- Object
- RKelly::CharRange
- 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
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
-
#initialize(from, to) ⇒ CharRange
constructor
A new instance of CharRange.
-
#next(string) ⇒ Object
Creates a new range that immediately follows this one and contains the given string.
- #to_s ⇒ Object (also: #inspect)
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
#from ⇒ Object (readonly)
Returns the value of attribute from.
11 12 13 |
# File 'lib/rkelly/char_range.rb', line 11 def from @from end |
#to ⇒ Object (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_s ⇒ Object Also known as: inspect
24 25 26 |
# File 'lib/rkelly/char_range.rb', line 24 def to_s "<#{@from}...#{@to}>" end |