Class: C::Node::Pos

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/cast/node.rb

Overview

A position in a source file. All Nodes may have one in their #pos attribute.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, line_num, col_num) ⇒ Pos

Returns a new instance of Pos.



724
725
726
727
728
# File 'lib/cast/node.rb', line 724

def initialize(filename, line_num, col_num)
  @filename = filename
  @line_num = line_num
  @col_num  = col_num
end

Instance Attribute Details

#col_numObject

Returns the value of attribute col_num.



723
724
725
# File 'lib/cast/node.rb', line 723

def col_num
  @col_num
end

#filenameObject

Returns the value of attribute filename.



723
724
725
# File 'lib/cast/node.rb', line 723

def filename
  @filename
end

#line_numObject

Returns the value of attribute line_num.



723
724
725
# File 'lib/cast/node.rb', line 723

def line_num
  @line_num
end

Instance Method Details

#<=>(x) ⇒ Object



732
733
734
735
736
# File 'lib/cast/node.rb', line 732

def <=>(x)
  return nil if self.filename != x.filename
  return (self.line_num <=> x.line_num).nonzero? ||
    self.col_num <=> x.col_num
end

#to_sObject



729
730
731
# File 'lib/cast/node.rb', line 729

def to_s
  (@filename ? "#@filename:" : '') << "#@line_num:#@col_num"
end