Class: Parslet::Position
- Inherits:
-
Object
- Object
- Parslet::Position
- Includes:
- Comparable
- Defined in:
- lib/parslet/position.rb
Overview
Encapsules the concept of a position inside a string.
Instance Attribute Summary collapse
-
#bytepos ⇒ Object
readonly
Returns the value of attribute bytepos.
Instance Method Summary collapse
- #<=>(b) ⇒ Object
- #charpos ⇒ Object
-
#initialize(string, bytepos) ⇒ Position
constructor
A new instance of Position.
Constructor Details
#initialize(string, bytepos) ⇒ Position
Returns a new instance of Position.
9 10 11 12 |
# File 'lib/parslet/position.rb', line 9 def initialize string, bytepos @string = string @bytepos = bytepos end |
Instance Attribute Details
#bytepos ⇒ Object (readonly)
Returns the value of attribute bytepos.
5 6 7 |
# File 'lib/parslet/position.rb', line 5 def bytepos @bytepos end |
Instance Method Details
#<=>(b) ⇒ Object
18 19 20 |
# File 'lib/parslet/position.rb', line 18 def <=> b self.bytepos <=> b.bytepos end |
#charpos ⇒ Object
14 15 16 |
# File 'lib/parslet/position.rb', line 14 def charpos @string.byteslice(0, @bytepos).size end |