Class: Fir::Cursor
- Inherits:
-
Object
- Object
- Fir::Cursor
- Defined in:
- lib/fir/cursor.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #blank? ⇒ Boolean
- #clone ⇒ Object
- #down ⇒ Object
-
#initialize(x, y) ⇒ Cursor
constructor
A new instance of Cursor.
- #left(n) ⇒ Object
- #right(n) ⇒ Object
- #up ⇒ Object
Constructor Details
#initialize(x, y) ⇒ Cursor
Returns a new instance of Cursor.
9 10 11 12 |
# File 'lib/fir/cursor.rb', line 9 def initialize(x, y) @x = x @y = y end |
Instance Attribute Details
#x ⇒ Object (readonly)
Returns the value of attribute x.
6 7 8 |
# File 'lib/fir/cursor.rb', line 6 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
7 8 9 |
# File 'lib/fir/cursor.rb', line 7 def y @y end |
Class Method Details
.blank ⇒ Object
14 15 16 |
# File 'lib/fir/cursor.rb', line 14 def self.blank new(0, 0) end |
Instance Method Details
#==(other) ⇒ Object
38 39 40 |
# File 'lib/fir/cursor.rb', line 38 def ==(other) other.x == x && other.y == y end |
#blank? ⇒ Boolean
42 43 44 |
# File 'lib/fir/cursor.rb', line 42 def blank? x.zero? && y.zero? end |
#clone ⇒ Object
18 19 20 |
# File 'lib/fir/cursor.rb', line 18 def clone self.class.new(x, y) end |
#down ⇒ Object
26 27 28 |
# File 'lib/fir/cursor.rb', line 26 def down self.class.new(x, y + 1) end |
#left(n) ⇒ Object
30 31 32 |
# File 'lib/fir/cursor.rb', line 30 def left(n) self.class.new(x - n, y) end |
#right(n) ⇒ Object
34 35 36 |
# File 'lib/fir/cursor.rb', line 34 def right(n) self.class.new(x + n, y) end |
#up ⇒ Object
22 23 24 |
# File 'lib/fir/cursor.rb', line 22 def up self.class.new(x, y - 1) end |