Class: MiniRuby::Position

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

Overview

A position of a single character in a piece of text

Constant Summary collapse

ZERO =
Position.new(0)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(char_index) ⇒ Position

: (Integer char_index) -> void



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

def initialize(char_index)
  @char_index = char_index
end

Instance Attribute Details

#char_indexObject (readonly)

: Integer



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

def char_index
  @char_index
end

Instance Method Details

#==(other) ⇒ Object

: (Object other) -> bool



20
21
22
23
24
# File 'lib/miniruby/position.rb', line 20

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

  @char_index == other.char_index
end

#inspectObject

: -> String



27
28
29
# File 'lib/miniruby/position.rb', line 27

def inspect
  "P(#{char_index.inspect})"
end