Class: Herb::Position

Inherits:
Object
  • Object
show all
Defined in:
lib/herb/position.rb,
ext/herb/extension.c

Overview

: type serialized_position = { line: Integer, column: Integer }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line, column) ⇒ Position

: (Integer, Integer) -> void



11
12
13
14
# File 'lib/herb/position.rb', line 11

def initialize(line, column)
  @line = line
  @column = column
end

Instance Attribute Details

#columnObject (readonly)

: Integer



8
9
10
# File 'lib/herb/position.rb', line 8

def column
  @column
end

#lineObject (readonly)

: Integer



7
8
9
# File 'lib/herb/position.rb', line 7

def line
  @line
end

Class Method Details

.[](line, column) ⇒ Object

: (Integer, Integer) -> Position



17
18
19
# File 'lib/herb/position.rb', line 17

def self.[](line, column)
  new(line, column)
end

.from(line, column) ⇒ Object

: (Integer, Integer) -> Position



22
23
24
# File 'lib/herb/position.rb', line 22

def self.from(line, column)
  new(line, column)
end

Instance Method Details

#inspectObject

: () -> String



42
43
44
# File 'lib/herb/position.rb', line 42

def inspect
  %(#<Herb::Position #{tree_inspect}>)
end

#to_hashObject

: () -> serialized_position



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

def to_hash
  { line: line, column: column } #: Herb::serialized_position
end

#to_json(state = nil) ⇒ Object

: (?untyped) -> String



32
33
34
# File 'lib/herb/position.rb', line 32

def to_json(state = nil)
  to_hash.to_json(state)
end

#tree_inspectObject

: () -> String



37
38
39
# File 'lib/herb/position.rb', line 37

def tree_inspect
  "(#{line}:#{column})"
end