Class: TTYString::Cursor
- Inherits:
-
Object
- Object
- TTYString::Cursor
- Defined in:
- lib/tty_string/cursor.rb
Overview
point on a screen. you can move it
Instance Attribute Summary collapse
-
#col ⇒ Object
Returns the value of attribute col.
-
#row ⇒ Object
Returns the value of attribute row.
Instance Method Summary collapse
- #down(count = 1) ⇒ Object
-
#initialize(row = 0, col = 0) ⇒ Cursor
constructor
A new instance of Cursor.
- #left(count = 1) ⇒ Object
- #right(count = 1) ⇒ Object
- #to_ary ⇒ Object (also: #to_a)
- #up(count = 1) ⇒ Object
Constructor Details
#initialize(row = 0, col = 0) ⇒ Cursor
Returns a new instance of Cursor.
8 9 10 11 |
# File 'lib/tty_string/cursor.rb', line 8 def initialize(row = 0, col = 0) @row = row @col = col end |
Instance Attribute Details
#col ⇒ Object
Returns the value of attribute col.
6 7 8 |
# File 'lib/tty_string/cursor.rb', line 6 def col @col end |
#row ⇒ Object
Returns the value of attribute row.
6 7 8 |
# File 'lib/tty_string/cursor.rb', line 6 def row @row end |
Instance Method Details
#down(count = 1) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/tty_string/cursor.rb', line 37 def down(count = 1) count = count.to_i raise ArgumentError unless count >= 0 self.row += count end |
#left(count = 1) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/tty_string/cursor.rb', line 23 def left(count = 1) count = count.to_i raise ArgumentError if count.negative? self.col -= count end |
#right(count = 1) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/tty_string/cursor.rb', line 44 def right(count = 1) count = count.to_i raise ArgumentError unless count >= 0 self.col += count end |
#to_ary ⇒ Object Also known as: to_a
51 52 53 |
# File 'lib/tty_string/cursor.rb', line 51 def to_ary [row, col] end |
#up(count = 1) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/tty_string/cursor.rb', line 30 def up(count = 1) count = count.to_i raise ArgumentError if count.negative? self.row -= count end |